{"input": "Returns a hash in the following format : { pod / web - 1 = > [ Pulling : pulling image hello - world : latest ( 1 events ) Pulled : Successfully pulled image hello - world : latest ( 1 events ) ] } [CODESPLIT] def fetch_events ( kubectl ) return { } unless exists? out , _err , st = kubectl . run ( \"get\" , \"events\" , \"--output=go-template=#{Event.go_template_for(type, name)}\" , log_failure : false ) return { } unless st . success? event_collector = Hash . new { | hash , key | hash [ key ] = [ ] } Event . extract_all_from_go_template_blob ( out ) . each_with_object ( event_collector ) do | candidate , events | events [ id ] << candidate . to_s if candidate . seen_since? ( @deploy_started_at - 5 . seconds ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Outputs the deferred summary information saved via [CODESPLIT] def print_summary ( status ) status_string = status . to_s . humanize . upcase if status == :success heading ( \"Result: \" , status_string , :green ) level = :info elsif status == :timed_out heading ( \"Result: \" , status_string , :yellow ) level = :fatal else heading ( \"Result: \" , status_string , :red ) level = :fatal end if ( actions_sentence = summary . actions_sentence . presence ) public_send ( level , actions_sentence ) blank_line ( level ) end summary . paragraphs . each do | para | msg_lines = para . split ( \"\\n\" ) msg_lines . each { | line | public_send ( level , line ) } blank_line ( level ) unless para == summary . paragraphs . last end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Things removed from default prune whitelist at https : // github . com / kubernetes / kubernetes / blob / 0dff56b4d88ec7551084bf89028dbeebf569620e / pkg / kubectl / cmd / apply . go#L411 : core / v1 / Namespace -- not namespaced core / v1 / PersistentVolume -- not namespaced core / v1 / Endpoints -- managed by services core / v1 / PersistentVolumeClaim -- would delete data core / v1 / ReplicationController -- superseded by deployments / replicasets extensions / v1beta1 / ReplicaSet -- managed by deployments [CODESPLIT] def predeploy_sequence before_crs = %w( ResourceQuota NetworkPolicy ) after_crs = %w( ConfigMap PersistentVolumeClaim ServiceAccount Role RoleBinding Secret Pod ) before_crs + cluster_resource_discoverer . crds . map ( :kind ) + after_crs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inspect the file referenced in the kubectl stderr to make it easier for developer to understand what s going on [CODESPLIT] def find_bad_files_from_kubectl_output ( line ) # stderr often contains one or more lines like the following, from which we can extract the file path(s): # Error from server (TypeOfError): error when creating \"/path/to/service-gqq5oh.yml\": Service \"web\" is invalid: line . scan ( %r{ \\S \\. \\S } ) . each_with_object ( [ ] ) do | matches , bad_files | matches . each do | path | content = File . read ( path ) if File . file? ( path ) bad_files << { filename : File . basename ( path ) , err : line , content : content } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "make sure to never prune the ejson - keys secret [CODESPLIT] def confirm_ejson_keys_not_prunable secret = ejson_provisioner . ejson_keys_secret return unless secret . dig ( \"metadata\" , \"annotations\" , KubernetesResource :: LAST_APPLIED_ANNOTATION ) @logger . error ( \"Deploy cannot proceed because protected resource \" \"Secret/#{EjsonSecretProvisioner::EJSON_KEYS_SECRET} would be pruned.\" ) raise EjsonPrunableError rescue Kubectl :: ResourceNotFoundError => e @logger . debug ( \"Secret/#{EjsonSecretProvisioner::EJSON_KEYS_SECRET} does not exist: #{e}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine the best compressor for the current system . This method returns the class not an instance of the class . [CODESPLIT] def for_current_system ( compressors ) family = Ohai [ \"platform_family\" ] if family == \"mac_os_x\" if compressors . include? ( :dmg ) return DMG end if compressors . include? ( :tgz ) return TGZ end end if compressors . include? ( :tgz ) return TGZ else log . info ( log_key ) { \"No compressor defined for `#{family}'.\" } return Null end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy all scripts in { Project#package_scripts_path } to the package directory . [CODESPLIT] def write_scripts SCRIPT_MAP . each do | script , _installp_name | source_path = File . join ( project . package_scripts_path , script . to_s ) if File . file? ( source_path ) log . debug ( log_key ) { \"Adding script `#{script}' to `#{scripts_staging_dir}'\" } copy_file ( source_path , scripts_staging_dir ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create the gen template for + mkinstallp + . [CODESPLIT] def write_gen_template # Get a list of all files files = FileSyncer . glob ( \"#{staging_dir}/**/*\" ) . reject do | path | # remove any files with spaces or braces. if path =~ / / log . warn ( log_key ) { \"Skipping packaging '#{path}' file due to whitespace or braces in filename\" } true end end files . map! do | path | # If paths have colons or commas, rename them and add them to a post-install, # post-sysck renaming script ('config') which is created if needed if path =~ / / alt = path . gsub ( / / , \"__\" ) log . debug ( log_key ) { \"Renaming #{path} to #{alt}\" } File . rename ( path , alt ) if File . exist? ( path ) # Create a config script if needed based on resources/bff/config.erb config_script_path = File . join ( scripts_staging_dir , \"config\" ) unless File . exist? config_script_path render_template ( resource_path ( \"config.erb\" ) , destination : \"#{scripts_staging_dir}/config\" , variables : { name : project . name , } ) end File . open ( File . join ( scripts_staging_dir , \"config\" ) , \"a\" ) do | file | file . puts \"mv '#{alt.gsub(/^#{staging_dir}/, '')}' '#{path.gsub(/^#{staging_dir}/, '')}'\" end path = alt end path . gsub ( / #{ staging_dir } / , \"\" ) end # Create a map of scripts that exist to inject into the template scripts = SCRIPT_MAP . inject ( { } ) do | hash , ( script , installp_key ) | staging_path = File . join ( scripts_staging_dir , script . to_s ) if File . file? ( staging_path ) hash [ installp_key ] = staging_path log . debug ( log_key ) { installp_key + \":\\n\" + File . read ( staging_path ) } end hash end render_template ( resource_path ( \"gen.template.erb\" ) , destination : File . join ( staging_dir , \"gen.template\" ) , variables : { name : safe_base_package_name , install_dir : project . install_dir , friendly_name : project . friendly_name , version : bff_version , description : project . description , files : files , scripts : scripts , } ) # Print the full contents of the rendered template file for mkinstallp's use log . debug ( log_key ) { \"Rendered Template:\\n\" + File . read ( File . join ( staging_dir , \"gen.template\" ) ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create the bff file using + mkinstallp + . [CODESPLIT] def create_bff_file # We are making the assumption that sudo exists. # Unforunately, the owner of the file in the staging directory is what # will be on the target machine, and mkinstallp can't tell you if that # is a bad thing (it usually is). # The match is so we only pick the lowest level of the project dir. # This implies that if we are in /tmp/staging/project/dir/things, # we will chown from 'project' on, rather than 'project/dir', which leaves # project owned by the build user (which is incorrect) # First - let's find out who we are. shellout! ( \"sudo chown -Rh 0:0 #{File.join(staging_dir, project.install_dir.match(/^\\/?(\\w+)/).to_s)}\" ) log . info ( log_key ) { \"Creating .bff file\" } # Since we want the owner to be root, we need to sudo the mkinstallp # command, otherwise it will not have access to the previously chowned # directory. shellout! ( \"sudo /usr/sbin/mkinstallp -d #{staging_dir} -T #{File.join(staging_dir, 'gen.template')}\" ) # Print the full contents of the inventory file generated by mkinstallp # from within the staging_dir's .info folder (where control files for the # packaging process are kept.) log . debug ( log_key ) do \"With .inventory file of:\\n\" + File . read ( \"#{File.join( staging_dir, '.info', \"#{safe_base_package_name}.inventory\" )}\" ) end # Copy the resulting package up to the package_dir FileSyncer . glob ( File . join ( staging_dir , \"tmp/*.bff\" ) ) . each do | bff | copy_file ( bff , File . join ( Config . package_dir , create_bff_file_name ) ) end ensure # chown back to original user's uid/gid so cleanup works correctly original_uid = shellout! ( \"id -u\" ) . stdout . chomp original_gid = shellout! ( \"id -g\" ) . stdout . chomp shellout! ( \"sudo chown -Rh #{original_uid}:#{original_gid} #{staging_dir}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Glob across the given pattern accounting for dotfiles removing Ruby s dumb idea to include + . + and + .. + as entries . [CODESPLIT] def glob ( pattern ) pattern = Pathname . new ( pattern ) . cleanpath . to_s Dir . glob ( pattern , File :: FNM_DOTMATCH ) . sort . reject do | file | basename = File . basename ( file ) IGNORED_FILES . include? ( basename ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Glob for all files under a given path / pattern removing Ruby s dumb idea to include + . + and + .. + as entries . [CODESPLIT] def all_files_under ( source , options = { } ) excludes = Array ( options [ :exclude ] ) . map do | exclude | [ exclude , \"#{exclude}/*\" ] end . flatten source_files = glob ( File . join ( source , \"**/*\" ) ) source_files = source_files . reject do | source_file | basename = relative_path_for ( source_file , source ) excludes . any? { | exclude | File . fnmatch? ( exclude , basename , File :: FNM_DOTMATCH ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy the files from + source + to + destination + while removing any files in + destination + that are not present in + source + . [CODESPLIT] def sync ( source , destination , options = { } ) unless File . directory? ( source ) raise ArgumentError , \"`source' must be a directory, but was a \" \"`#{File.ftype(source)}'! If you just want to sync a file, use \" \"the `copy' method instead.\" end source_files = all_files_under ( source , options ) # Ensure the destination directory exists FileUtils . mkdir_p ( destination ) unless File . directory? ( destination ) # Copy over the filtered source files source_files . each do | source_file | relative_path = relative_path_for ( source_file , source ) # Create the parent directory parent = File . join ( destination , File . dirname ( relative_path ) ) FileUtils . mkdir_p ( parent ) unless File . directory? ( parent ) case File . ftype ( source_file ) . to_sym when :directory FileUtils . mkdir_p ( \"#{destination}/#{relative_path}\" ) when :link target = File . readlink ( source_file ) Dir . chdir ( destination ) do FileUtils . ln_sf ( target , \"#{destination}/#{relative_path}\" ) end when :file source_stat = File . stat ( source_file ) # Detect 'files' which are hard links and use ln instead of cp to # duplicate them, provided their source is in place already if hardlink? source_stat if existing = hardlink_sources [ [ source_stat . dev , source_stat . ino ] ] FileUtils . ln ( existing , \"#{destination}/#{relative_path}\" , force : true ) else begin FileUtils . cp ( source_file , \"#{destination}/#{relative_path}\" ) rescue Errno :: EACCES FileUtils . cp_r ( source_file , \"#{destination}/#{relative_path}\" , remove_destination : true ) end hardlink_sources . store ( [ source_stat . dev , source_stat . ino ] , \"#{destination}/#{relative_path}\" ) end else # First attempt a regular copy. If we don't have write # permission on the File, open will probably fail with # EACCES (making it hard to sync files with permission # r--r--r--). Rescue this error and use cp_r's # :remove_destination option. begin FileUtils . cp ( source_file , \"#{destination}/#{relative_path}\" ) rescue Errno :: EACCES FileUtils . cp_r ( source_file , \"#{destination}/#{relative_path}\" , remove_destination : true ) end end else raise \"Unknown file type: `File.ftype(source_file)' at `#{source_file}'!\" end end # Remove any files in the destination that are not in the source files destination_files = glob ( \"#{destination}/**/*\" ) # Calculate the relative paths of files so we can compare to the # source. relative_source_files = source_files . map do | file | relative_path_for ( file , source ) end relative_destination_files = destination_files . map do | file | relative_path_for ( file , destination ) end # Remove any extra files that are present in the destination, but are # not in the source list extra_files = relative_destination_files - relative_source_files extra_files . each do | file | FileUtils . rm_rf ( File . join ( destination , file ) ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The relative path of the given + path + to the + parent + . [CODESPLIT] def relative_path_for ( path , parent ) Pathname . new ( path ) . relative_path_from ( Pathname . new ( parent ) ) . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine the packager ( s ) for the current system . This method returns the class not an instance of the class . [CODESPLIT] def for_current_system family = Ohai [ \"platform_family\" ] version = Ohai [ \"platform_version\" ] if family == \"solaris2\" && Chef :: Sugar :: Constraints :: Version . new ( version ) . satisfies? ( \">= 5.11\" ) family = \"ips\" elsif family == \"solaris2\" && Chef :: Sugar :: Constraints :: Version . new ( version ) . satisfies? ( \">= 5.10\" ) family = \"solaris\" end if klass = PLATFORM_PACKAGER_MAP [ family ] package_types = klass . is_a? ( Array ) ? klass : [ klass ] if package_types . include? ( APPX ) && ! Chef :: Sugar :: Constraints :: Version . new ( version ) . satisfies? ( \">= 6.2\" ) log . warn ( log_key ) { \"APPX generation is only supported on Windows versions 2012 and above\" } package_types -= [ APPX ] end package_types else log . warn ( log_key ) do \"Could not determine packager for `#{family}', defaulting \" \"to `makeself'!\" end [ Makeself ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Cleans any previously left over mounted disks . [CODESPLIT] def clean_disks log . info ( log_key ) { \"Cleaning previously mounted disks\" } existing_disks = shellout! ( \"mount | grep \\\"/Volumes/#{volume_name}\\\" | awk '{print $1}'\" ) existing_disks . stdout . lines . each do | existing_disk | existing_disk . chomp! Omnibus . logger . debug ( log_key ) do \"Detaching disk `#{existing_disk}' before starting dmg packaging.\" end shellout! ( \"hdiutil detach '#{existing_disk}'\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Attach the dmg storing a reference to the device for later use . [CODESPLIT] def attach_dmg @device ||= Dir . chdir ( staging_dir ) do log . info ( log_key ) { \"Attaching dmg as disk\" } cmd = shellout! <<-EOH . gsub ( / / , \"\" ) \\\\ \\\\ \\\\ \\\\ #{ writable_dmg } EOH cmd . stdout . strip end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy assets to dmg [CODESPLIT] def copy_assets_to_dmg log . info ( log_key ) { \"Copying assets into dmg\" } FileSyncer . glob ( \"#{resources_dir}/*\" ) . each do | file | FileUtils . cp_r ( file , \"/Volumes/#{volume_name}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create the icon for the volume using sips . [CODESPLIT] def set_volume_icon log . info ( log_key ) { \"Setting volume icon\" } icon = resource_path ( \"icon.png\" ) Dir . chdir ( staging_dir ) do shellout! <<-EOH . gsub ( / / , \"\" ) #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ icon } #{ volume_name } #{ volume_name } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Use Applescript to setup the DMG with pretty logos and colors . [CODESPLIT] def prettify_dmg log . info ( log_key ) { \"Making the dmg all pretty and stuff\" } render_template ( resource_path ( \"create_dmg.osascript.erb\" ) , destination : \"#{staging_dir}/create_dmg.osascript\" , variables : { volume_name : volume_name , pkg_name : packager . package_name , window_bounds : window_bounds , pkg_position : pkg_position , } ) Dir . chdir ( staging_dir ) do shellout! <<-EOH . gsub ( / / , \"\" ) #{ staging_dir } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compress the dmg using hdiutil and zlib . zlib offers better compression levels than bzip2 ( 10 . 4 + ) or LZFSE ( 10 . 11 + ) but takes longer to compress . We re willing to trade slightly longer build times for smaller package sizes . [CODESPLIT] def compress_dmg log . info ( log_key ) { \"Compressing dmg\" } Dir . chdir ( staging_dir ) do shellout! <<-EOH . gsub ( / / , \"\" ) #{ volume_name } #{ @device } \\\\ #{ writable_dmg } \\\\ \\\\ \\\\ \\\\ #{ package_path } #{ writable_dmg } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the dmg icon to our custom icon . [CODESPLIT] def set_dmg_icon log . info ( log_key ) { \"Setting dmg icon\" } Dir . chdir ( staging_dir ) do shellout! <<-EOH . gsub ( / / , \"\" ) #{ resource_path ( 'icon.png' ) } #{ resource_path ( 'icon.png' ) } #{ package_path } #{ package_path } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A set of transform rules that pkgmogrify will apply to the package manifest . [CODESPLIT] def write_transform_file render_template ( resource_path ( \"doc-transform.erb\" ) , destination : transform_file , variables : { pathdir : project . install_dir . split ( \"/\" ) [ 1 ] , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate package metadata [CODESPLIT] def write_pkg_metadata render_template ( resource_path ( \"gen.manifestfile.erb\" ) , destination : pkg_metadata_file , variables : { name : safe_base_package_name , fmri_package_name : fmri_package_name , description : project . description , summary : project . friendly_name , arch : safe_architecture , } ) # Append the contents of symlinks_file if it exists if symlinks_file File . open ( pkg_metadata_file , \"a\" ) do | symlink | symlink . write ( render_symlinks ) end end # Print the full contents of the rendered template file to generate package contents log . debug ( log_key ) { \"Rendered Template:\\n\" + File . read ( pkg_metadata_file ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Publish the IPS pkg into the local IPS repo [CODESPLIT] def publish_ips_pkg shellout! ( \"pkgrepo -s #{repo_dir} set publisher/prefix=#{publisher_prefix}\" ) shellout! ( \"pkgsend publish -s #{repo_dir} -d #{source_dir} #{pkg_manifest_file}.5.res\" ) log . info ( log_key ) { \"Published IPS package to repo: #{repo_dir}\" } repo_info = shellout ( \"pkg list -afv -g #{repo_dir}\" ) . stdout log . debug ( log_key ) do <<-EOH . strip #{ repo_info } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert a the published IPS pkg from the local repo into the more easily distributable * . p5p archive . [CODESPLIT] def export_pkg_archive_file # The destination file cannot already exist File . delete ( package_path ) if File . exist? ( package_path ) shellout! ( \"pkgrecv -s #{repo_dir} -a -d #{package_path} #{safe_base_package_name}\" ) log . info ( log_key ) { \"Exported IPS package archive: #{package_path}\" } list_pkgarchive = shellout ( \"pkgrepo list -s #{package_path} '*@latest'\" ) . stdout log . debug ( log_key ) do <<-EOH . strip #{ list_pkgarchive } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run the healthchecks against the given project . It is assumed that the project has already been built . [CODESPLIT] def run! measure ( \"Health check time\" ) do log . info ( log_key ) { \"Running health on #{project.name}\" } bad_libs = case Ohai [ \"platform\" ] when \"mac_os_x\" health_check_otool when \"aix\" health_check_aix when \"windows\" # TODO: objdump -p will provided a very limited check of # explicit dependencies on windows. Most dependencies are # implicit and hence not detected. log . warn ( log_key ) { \"Skipping dependency health checks on Windows.\" } { } else health_check_ldd end unresolved = [ ] unreliable = [ ] detail = [ ] if bad_libs . keys . length > 0 bad_libs . each do | name , lib_hash | lib_hash . each do | lib , linked_libs | linked_libs . each do | linked , count | if linked =~ / / unresolved << lib unless unresolved . include? lib else unreliable << linked unless unreliable . include? linked end detail << \"#{name}|#{lib}|#{linked}|#{count}\" end end end log . error ( log_key ) { \"Failed!\" } bad_omnibus_libs , bad_omnibus_bins = bad_libs . keys . partition { | k | k . include? \"embedded/lib\" } log . error ( log_key ) do out = \"The following libraries have unsafe or unmet dependencies:\\n\" bad_omnibus_libs . each do | lib | out << \"    --> #{lib}\\n\" end out end log . error ( log_key ) do out = \"The following binaries have unsafe or unmet dependencies:\\n\" bad_omnibus_bins . each do | bin | out << \"    --> #{bin}\\n\" end out end if unresolved . length > 0 log . error ( log_key ) do out = \"The following requirements could not be resolved:\\n\" unresolved . each do | lib | out << \"    --> #{lib}\\n\" end out end end if unreliable . length > 0 log . error ( log_key ) do out = \"The following libraries cannot be guaranteed to be on \" out << \"target systems:\\n\" unreliable . each do | lib | out << \"    --> #{lib}\\n\" end out end end log . error ( log_key ) do out = \"The precise failures were:\\n\" detail . each do | line | item , dependency , location , count = line . split ( \"|\" ) reason = location =~ / / ? \"Unresolved dependency\" : \"Unsafe dependency\" out << \"    --> #{item}\\n\" out << \"    DEPENDS ON: #{dependency}\\n\" out << \"      COUNT: #{count}\\n\" out << \"      PROVIDED BY: #{location}\\n\" out << \"      FAILED BECAUSE: #{reason}\\n\" end out end raise HealthCheckFailed end conflict_map = { } conflict_map = relocation_check if relocation_checkable? if conflict_map . keys . length > 0 log . warn ( log_key ) { \"Multiple dlls with overlapping images detected\" } conflict_map . each do | lib_name , data | base = data [ :base ] size = data [ :size ] next_valid_base = data [ :base ] + data [ :size ] log . warn ( log_key ) do out = \"Overlapping dll detected:\\n\" out << \"    #{lib_name} :\\n\" out << \"    IMAGE BASE: #{hex}\\n\" % base out << \"    IMAGE SIZE: #{hex} (#{size} bytes)\\n\" % size out << \"    NEXT VALID BASE: #{hex}\\n\" % next_valid_base out << \"    CONFLICTS:\\n\" data [ :conflicts ] . each do | conflict_name | cbase = conflict_map [ conflict_name ] [ :base ] csize = conflict_map [ conflict_name ] [ :size ] out << \"    - #{conflict_name} #{hex} + #{hex}\\n\" % [ cbase , csize ] end out end end # Don't raise an error yet. This is only bad for FIPS mode. end true end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check dll image location overlap / conflicts on windows . [CODESPLIT] def relocation_check conflict_map = { } embedded_bin = \"#{project.install_dir}/embedded/bin\" Dir . glob ( \"#{embedded_bin}/*.dll\" ) do | lib_path | log . debug ( log_key ) { \"Analyzing dependencies for #{lib_path}\" } File . open ( lib_path , \"rb\" ) do | f | dump = PEdump . new ( lib_path ) pe = dump . pe f # Don't scan dlls for a different architecture. next if windows_arch_i386? == pe . x64? lib_name = File . basename ( lib_path ) base = pe . ioh . ImageBase size = pe . ioh . SizeOfImage conflicts = [ ] # This can be done more smartly but O(n^2) is just fine for n = small conflict_map . each do | candidate_name , details | unless details [ :base ] >= base + size || details [ :base ] + details [ :size ] <= base details [ :conflicts ] << lib_name conflicts << candidate_name end end conflict_map [ lib_name ] = { base : base , size : size , conflicts : conflicts , } log . debug ( log_key ) { \"Discovered #{lib_name} at #{hex} + #{hex}\" % [ base , size ] } end end # Filter out non-conflicting entries. conflict_map . delete_if do | lib_name , details | details [ :conflicts ] . empty? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run healthchecks against otool . [CODESPLIT] def health_check_otool current_library = nil bad_libs = { } read_shared_libs ( \"find #{project.install_dir}/ -type f | egrep '\\.(dylib|bundle)$' | xargs otool -L\" ) do | line | case line when / / current_library = Regexp . last_match [ 1 ] when / \\s \\( \\) / linked = Regexp . last_match [ 1 ] name = File . basename ( linked ) bad_libs = check_for_bad_library ( bad_libs , current_library , name , linked ) end end bad_libs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run healthchecks against aix . [CODESPLIT] def health_check_aix current_library = nil bad_libs = { } read_shared_libs ( \"find #{project.install_dir}/ -type f | xargs file | grep \\\"RISC System\\\" | awk -F: '{print $1}' | xargs -n 1 ldd\" ) do | line | case line when / / current_library = Regexp . last_match [ 1 ] log . debug ( log_key ) { \"Analyzing dependencies for #{current_library}\" } when / \\s / name = Regexp . last_match [ 1 ] linked = Regexp . last_match [ 1 ] bad_libs = check_for_bad_library ( bad_libs , current_library , name , linked ) when / / # ignore non-executable files else log . warn ( log_key ) { \"Line did not match for #{current_library}\\n#{line}\" } end end bad_libs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run healthchecks against ldd . [CODESPLIT] def health_check_ldd regexp_ends = \".*(\" + IGNORED_ENDINGS . map { | e | e . gsub ( / \\. / , '\\.' ) } . join ( \"|\" ) + \")$\" regexp_patterns = IGNORED_PATTERNS . map { | e | \".*\" + e . gsub ( / \\/ / , '\\/' ) + \".*\" } . join ( \"|\" ) regexp = regexp_ends + \"|\" + regexp_patterns current_library = nil bad_libs = { } read_shared_libs ( \"find #{project.install_dir}/ -type f -regextype posix-extended ! -regex '#{regexp}' | xargs ldd\" ) do | line | case line when / / current_library = Regexp . last_match [ 1 ] log . debug ( log_key ) { \"Analyzing dependencies for #{current_library}\" } when / \\s \\= \\> \\s \\( \\) / name = Regexp . last_match [ 1 ] linked = Regexp . last_match [ 2 ] bad_libs = check_for_bad_library ( bad_libs , current_library , name , linked ) when / \\s \\( \\) / next when / \\s / next when / \\s / next when / \\s / next when / \\s / next when / \\s / # ignore non-executable files else log . warn ( log_key ) do \"Line did not match for #{current_library}\\n#{line}\" end end end bad_libs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The list of whitelisted ( ignored ) files from the project and softwares . [CODESPLIT] def whitelist_files project . library . components . inject ( [ ] ) do | array , component | array += component . whitelist_files array end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given command yielding each line . [CODESPLIT] def read_shared_libs ( command ) cmd = shellout ( command ) cmd . stdout . each_line do | line | yield line end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check the given path and library for bad libraries . [CODESPLIT] def check_for_bad_library ( bad_libs , current_library , name , linked ) safe = nil whitelist_libs = case Ohai [ \"platform\" ] when \"arch\" ARCH_WHITELIST_LIBS when \"mac_os_x\" MAC_WHITELIST_LIBS when \"solaris2\" SOLARIS_WHITELIST_LIBS when \"smartos\" SMARTOS_WHITELIST_LIBS when \"freebsd\" FREEBSD_WHITELIST_LIBS when \"aix\" AIX_WHITELIST_LIBS else WHITELIST_LIBS end whitelist_libs . each do | reg | safe ||= true if reg . match ( name ) end whitelist_files . each do | reg | safe ||= true if reg . match ( current_library ) end log . debug ( log_key ) { \"  --> Dependency: #{name}\" } log . debug ( log_key ) { \"  --> Provided by: #{linked}\" } if ! safe && linked !~ Regexp . new ( project . install_dir ) log . debug ( log_key ) { \"    -> FAILED: #{current_library} has unsafe dependencies\" } bad_libs [ current_library ] ||= { } bad_libs [ current_library ] [ name ] ||= { } if bad_libs [ current_library ] [ name ] . key? ( linked ) bad_libs [ current_library ] [ name ] [ linked ] += 1 else bad_libs [ current_library ] [ name ] [ linked ] = 1 end else log . debug ( log_key ) { \"    -> PASSED: #{name} is either whitelisted or safely provided.\" } end bad_libs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the digest of the file at the given path . Files are read in binary chunks to prevent Ruby from exploding . [CODESPLIT] def digest ( path , type = :md5 ) digest = digest_from_type ( type ) update_with_file_contents ( digest , path ) digest . hexdigest end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the digest of a directory at the given path . Each file in the directory is read in binary chunks to prevent excess memory usage . Filesystem entries of all types are included in the digest including directories links and sockets . The contents of non - file entries are represented as : [CODESPLIT] def digest_directory ( path , type = :md5 , options = { } ) digest = digest_from_type ( type ) log . info ( log_key ) { \"Digesting #{path} with #{type}\" } FileSyncer . all_files_under ( path , options ) . each do | filename | # Calculate the filename relative to the given path. Since directories # are SHAed according to their filepath, two difference directories on # disk would have different SHAs even if they had the same content. relative = Pathname . new ( filename ) . relative_path_from ( Pathname . new ( path ) ) case ftype = File . ftype ( filename ) when \"file\" update_with_string ( digest , \"#{ftype} #{relative}\" ) update_with_file_contents ( digest , filename ) else update_with_string ( digest , \"#{ftype} #{relative}\" ) end end digest . hexdigest end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new instance of the { Digest } class that corresponds to the given type . [CODESPLIT] def digest_from_type ( type ) id = type . to_s . upcase instance = OpenSSL :: Digest . const_get ( id ) . new end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update the digest with the given contents of the file reading in small chunks to reduce memory . This method will update the given + digest + parameter but returns nothing . [CODESPLIT] def update_with_file_contents ( digest , filename ) File . open ( filename ) do | io | while ( chunk = io . read ( 1024 * 8 ) ) digest . update ( chunk ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new publisher from the given pattern . [CODESPLIT] def packages @packages ||= begin publish_packages = Array . new build_packages = FileSyncer . glob ( @pattern ) . map { | path | Package . new ( path ) } if @options [ :platform_mappings ] # the platform map is a simple hash with publish to build platform mappings @options [ :platform_mappings ] . each_pair do | build_platform , publish_platforms | # Splits `ubuntu-12.04` into `ubuntu` and `12.04` build_platform , build_platform_version = build_platform . rpartition ( \"-\" ) - %w{ - } # locate the package for the build platform packages = build_packages . select do | p | p . metadata [ :platform ] == build_platform && p . metadata [ :platform_version ] == build_platform_version end if packages . empty? log . warn ( log_key ) do \"Could not locate a package for build platform #{build_platform}-#{build_platform_version}. \" \"Publishing will be skipped for: #{publish_platforms.join(', ')}\" end end publish_platforms . each do | publish_platform | publish_platform , publish_platform_version = publish_platform . rpartition ( \"-\" ) - %w{ - } packages . each do | p | # create a copy of our package before mucking with its metadata publish_package = p . dup publish_metadata = p . metadata . dup . to_hash # override the platform and platform version in the metadata publish_metadata [ :platform ] = publish_platform publish_metadata [ :platform_version ] = publish_platform_version # Set the updated metadata on the package object publish_package . metadata = Metadata . new ( publish_package , publish_metadata ) publish_packages << publish_package end end end else publish_packages . concat ( build_packages ) end if publish_packages . empty? log . info ( log_key ) { \"No packages found, skipping publish\" } end publish_packages end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Construct the intermediate build product . It can be installed with the Installer . app but doesn t contain the data needed to customize the installer UI . [CODESPLIT] def build_component_pkg command = <<-EOH . gsub ( / / , \"\" ) \\\\ #{ safe_identifier } \\\\ #{ safe_version } \\\\ #{ scripts_dir } \\\\ #{ project . install_dir } \\\\ #{ project . install_dir } \\\\ #{ component_pkg } EOH Dir . chdir ( staging_dir ) do shellout! ( command ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the Distribution file to the staging area . This method generates the content of the Distribution file which is used by + productbuild + to select the component packages to include in the product package . [CODESPLIT] def write_distribution_file render_template ( resource_path ( \"distribution.xml.erb\" ) , destination : \"#{staging_dir}/Distribution\" , mode : 0600 , variables : { friendly_name : project . friendly_name , identifier : safe_identifier , version : safe_version , component_pkg : component_pkg , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Construct the product package . The generated package is the final build product that is shipped to end users . [CODESPLIT] def build_product_pkg command = <<-EOH . gsub ( / / , \"\" ) \\\\ #{ staging_dir } \\\\ #{ resources_dir } \\\\ EOH command << %Q{  --sign \"#{signing_identity}\" \\\\\\n} if signing_identity command << %Q{  \"#{final_pkg}\"} command << %Q{\\n} Dir . chdir ( staging_dir ) do shellout! ( command ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the PKG - ready version converting any invalid characters to dashes ( + - + ) . [CODESPLIT] def safe_version if project . build_version =~ / \\A \\. \\+ \\- \\z / project . build_version . dup else converted = project . build_version . gsub ( / \\. \\+ \\- / , \"-\" ) log . warn ( log_key ) do \"The `version' component of Mac package names can only include \" \"alphabetical characters (a-z, A-Z), numbers (0-9), dots (.), \" \"plus signs (+), and dashes (-). Converting \" \"`#{project.build_version}' to `#{converted}'.\" end converted end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine how wide a column should be taking into account both the column name as well as all data in that column . If no data will be stored in the column the width is 0 ( i . e . nothing should be printed not even the column header ) [CODESPLIT] def column_width ( items , column_name ) widest_item = items . max_by ( :size ) if widest_item widest = ( widest_item . size >= column_name . size ) ? widest_item : column_name widest . size + PADDING else 0 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fetch any new files by copying them to the + project_dir + . [CODESPLIT] def fetch log . info ( log_key ) { \"Copying from `#{source_file}'\" } create_required_directories FileUtils . cp ( source_file , target_file ) # Reset target shasum on every fetch @target_shasum = nil target_shasum end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The order in which each Software component should be built . The order is based on the order of #components optimized to move top - level dependencies later in the build order to make the git caching feature more effective . It is assumed that #components is already sorted in a valid dependency order . The optimization works as follows : [CODESPLIT] def build_order head = [ ] tail = [ ] @components . each do | component | if head . length == 0 head << component elsif @project . dependencies . include? ( component . name ) && @components . none? { | c | c . dependencies . include? ( component . name ) } tail << component else head << component end end [ head , tail ] . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The artifact object that corresponds to this package . [CODESPLIT] def artifact_for ( artifact ) md5 = artifact . respond_to? ( :metadata ) ? artifact . metadata [ :md5 ] : digest ( artifact . path , :md5 ) sha1 = artifact . respond_to? ( :metadata ) ? artifact . metadata [ :sha1 ] : digest ( artifact . path , :sha1 ) Artifactory :: Resource :: Artifact . new ( local_path : artifact . path , client : client , checksums : { \"md5\" => md5 , \"sha1\" => sha1 , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The build object that corresponds to this package . [CODESPLIT] def build_for ( packages ) metadata = packages . first . metadata name = metadata [ :name ] # Attempt to load the version manifest data from the packages metadata manifest = if version_manifest = metadata [ :version_manifest ] Manifest . from_hash ( version_manifest ) else Manifest . new ( metadata [ :version ] , # we already know the `version_manifest` entry is # missing so we can't pull in the `build_git_revision` nil , metadata [ :license ] ) end # Upload the actual package log . info ( log_key ) { \"Saving build info for #{name}, Build ##{manifest.build_version}\" } Artifactory :: Resource :: Build . new ( client : client , name : name , number : manifest . build_version , vcs_revision : manifest . build_git_revision , build_agent : { name : \"omnibus\" , version : Omnibus :: VERSION , } , modules : [ { # com.getchef:chef-server:12.0.0 id : [ Config . artifactory_base_path . tr ( \"/\" , \".\" ) , name , manifest . build_version , ] . join ( \":\" ) , artifacts : packages . map do | package | [ { type : File . extname ( package . path ) . split ( \".\" ) . last , sha1 : package . metadata [ :sha1 ] , md5 : package . metadata [ :md5 ] , name : package . metadata [ :basename ] , } , { type : File . extname ( package . metadata . path ) . split ( \".\" ) . last , sha1 : digest ( package . metadata . path , :sha1 ) , md5 : digest ( package . metadata . path , :md5 ) , name : File . basename ( package . metadata . path ) , } , ] end . flatten , } , ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The Artifactory client object to communicate with the Artifactory API . [CODESPLIT] def client @client ||= Artifactory :: Client . new ( endpoint : Config . artifactory_endpoint , username : Config . artifactory_username , password : Config . artifactory_password , ssl_pem_file : Config . artifactory_ssl_pem_file , ssl_verify : Config . artifactory_ssl_verify , proxy_username : Config . artifactory_proxy_username , proxy_password : Config . artifactory_proxy_password , proxy_address : Config . artifactory_proxy_address , proxy_port : Config . artifactory_proxy_port ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The metadata for this package . [CODESPLIT] def metadata_properties_for ( package ) metadata = { \"omnibus.project\" => package . metadata [ :name ] , \"omnibus.platform\" => package . metadata [ :platform ] , \"omnibus.platform_version\" => package . metadata [ :platform_version ] , \"omnibus.architecture\" => package . metadata [ :arch ] , \"omnibus.version\" => package . metadata [ :version ] , \"omnibus.iteration\" => package . metadata [ :iteration ] , \"omnibus.license\" => package . metadata [ :license ] , \"omnibus.md5\" => package . metadata [ :md5 ] , \"omnibus.sha1\" => package . metadata [ :sha1 ] , \"omnibus.sha256\" => package . metadata [ :sha256 ] , \"omnibus.sha512\" => package . metadata [ :sha512 ] , \"md5\" => package . metadata [ :md5 ] , \"sha1\" => package . metadata [ :sha1 ] , \"sha256\" => package . metadata [ :sha256 ] , \"sha512\" => package . metadata [ :sha512 ] , } . tap do | h | if build_record? h [ \"build.name\" ] = package . metadata [ :name ] h [ \"build.number\" ] = package . metadata [ :version ] end end metadata end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The path where the package will live inside of the Artifactory repository . This is dynamically computed from the values in the project definition and the package metadata . [CODESPLIT] def remote_path_for ( package ) File . join ( Config . artifactory_base_path , Config . artifactory_publish_pattern % package . metadata ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!group DSL methods -------------------------------------------------- [CODESPLIT] def upgrade_code ( val = NULL ) if null? ( val ) @upgrade_code || raise ( MissingRequiredAttribute . new ( self , :upgrade_code , \"2CD7259C-776D-4DDB-A4C8-6E544E580AA1\" ) ) else unless val . is_a? ( String ) raise InvalidValue . new ( :upgrade_code , \"be a String\" ) end @upgrade_code = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or retrieve the custom msi building parameters . [CODESPLIT] def parameters ( val = NULL ) if null? ( val ) @parameters || { } else unless val . is_a? ( Hash ) raise InvalidValue . new ( :parameters , \"be a Hash\" ) end @parameters = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the wix light extensions to load [CODESPLIT] def wix_light_extension ( extension ) unless extension . is_a? ( String ) raise InvalidValue . new ( :wix_light_extension , \"be an String\" ) end wix_light_extensions << extension end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Signal delay validation for wix light [CODESPLIT] def wix_light_delay_validation ( val = false ) unless val . is_a? ( TrueClass ) || val . is_a? ( FalseClass ) raise InvalidValue . new ( :iwix_light_delay_validation , \"be TrueClass or FalseClass\" ) end @delay_validation ||= val unless @delay_validation return \"\" end \"-sval\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the wix candle extensions to load [CODESPLIT] def wix_candle_extension ( extension ) unless extension . is_a? ( String ) raise InvalidValue . new ( :wix_candle_extension , \"be an String\" ) end wix_candle_extensions << extension end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Discovers a path to a gem / file included in a gem under the install directory . [CODESPLIT] def gem_path ( glob = NULL ) unless glob . is_a? ( String ) || null? ( glob ) raise InvalidValue . new ( :glob , \"be an String\" ) end install_path = Pathname . new ( project . install_dir ) # Find path in which the Chef gem is installed search_pattern = install_path . join ( \"**\" , \"gems\" ) search_pattern = search_pattern . join ( glob ) unless null? ( glob ) file_paths = Pathname . glob ( search_pattern ) . find raise \"Could not find `#{search_pattern}'!\" if file_paths . none? raise \"Multiple possible matches of `#{search_pattern}'! : #{file_paths}\" if file_paths . count > 1 file_paths . first . relative_path_from ( install_path ) . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the localization file into the staging directory . [CODESPLIT] def write_localization_file render_template ( resource_path ( \"localization-#{localization}.wxl.erb\" ) , destination : \"#{staging_dir}/localization-#{localization}.wxl\" , variables : { name : project . package_name , friendly_name : project . friendly_name , maintainer : project . maintainer , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the parameters file into the staging directory . [CODESPLIT] def write_parameters_file render_template ( resource_path ( \"parameters.wxi.erb\" ) , destination : \"#{staging_dir}/parameters.wxi\" , variables : { name : project . package_name , friendly_name : project . friendly_name , maintainer : project . maintainer , upgrade_code : upgrade_code , parameters : parameters , version : windows_package_version , display_version : msi_display_version , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the source file into the staging directory . [CODESPLIT] def write_source_file paths = [ ] # Remove C:/ install_dir = project . install_dir . split ( \"/\" ) [ 1 .. - 1 ] . join ( \"/\" ) # Grab all parent paths Pathname . new ( install_dir ) . ascend do | path | paths << path . to_s end # Create the hierarchy hierarchy = paths . reverse . inject ( { } ) do | hash , path | hash [ File . basename ( path ) ] = path . gsub ( / / , \"\" ) . upcase + \"LOCATION\" hash end # The last item in the path MUST be named PROJECTLOCATION or else space # robots will cause permanent damage to you and your family. hierarchy [ hierarchy . keys . last ] = \"PROJECTLOCATION\" # If the path hierarchy is > 1, the customizable installation directory # should default to the second-to-last item in the hierarchy. If the # hierarchy is smaller than that, then just use the system drive. wix_install_dir = if hierarchy . size > 1 hierarchy . to_a [ - 2 ] [ 1 ] else \"WINDOWSVOLUME\" end render_template ( resource_path ( \"source.wxs.erb\" ) , destination : \"#{staging_dir}/source.wxs\" , variables : { name : project . package_name , friendly_name : project . friendly_name , maintainer : project . maintainer , hierarchy : hierarchy , fastmsi : fast_msi , wix_install_dir : wix_install_dir , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the bundle file into the staging directory . [CODESPLIT] def write_bundle_file render_template ( resource_path ( \"bundle.wxs.erb\" ) , destination : \"#{staging_dir}/bundle.wxs\" , variables : { name : project . package_name , friendly_name : project . friendly_name , maintainer : project . maintainer , upgrade_code : upgrade_code , parameters : parameters , version : windows_package_version , display_version : msi_display_version , msi : windows_safe_path ( Config . package_dir , msi_name ) , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the shell command to create a zip file that contains the contents of the project install directory [CODESPLIT] def zip_command <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ windows_safe_path ( staging_dir ) } \\\\ #{ project . name } #{ windows_safe_path ( project . install_dir ) } \\\\ EOH end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the shell command to run heat in order to create a a WIX manifest of project files to be packaged into the MSI [CODESPLIT] def heat_command if fast_msi <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ project . name } EOH else <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ windows_safe_path ( project . install_dir ) } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the shell command to complie the project WIX files [CODESPLIT] def candle_command ( is_bundle : false ) if is_bundle <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ wix_candle_flags } #{ wix_extension_switches ( wix_candle_extensions ) } #{ windows_safe_path ( File . expand_path ( Config . cache_dir ) ) } #{ windows_safe_path ( staging_dir , 'bundle.wxs' ) } EOH else <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ wix_candle_flags } #{ wix_extension_switches ( wix_candle_extensions ) } #{ windows_safe_path ( project . install_dir ) } #{ windows_safe_path ( staging_dir , 'source.wxs' ) } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the shell command to link the project WIX object files [CODESPLIT] def light_command ( out_file , is_bundle : false ) if is_bundle <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ wix_light_delay_validation } #{ wix_extension_switches ( wix_light_extensions ) } #{ localization } #{ windows_safe_path ( staging_dir , \"localization-#{localization}.wxl\" ) } #{ out_file } EOH else <<-EOH . split . join ( \" \" ) . squeeze ( \" \" ) . strip #{ wix_light_delay_validation } #{ wix_extension_switches ( wix_light_extensions ) } #{ localization } #{ windows_safe_path ( staging_dir , \"localization-#{localization}.wxl\" ) } #{ out_file } EOH end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Callback that is called by software objects to determine the version . [CODESPLIT] def resolve ( dependency ) if from_dependency? && version_dependency == dependency . name construct_build_version ( dependency ) log . info ( log_key ) { \"Build Version is set to '#{build_version}'\" } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Append the build_start_time to the given string if Config . append_timestamp is true [CODESPLIT] def maybe_append_timestamp ( version ) if Config . append_timestamp && ! has_timestamp? ( version ) [ version , Omnibus :: BuildVersion . build_start_time ] . join ( \"+\" ) else version end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns true if a given version string Looks like it was already created with a function that added a timestamp . The goal of this is to avoid breaking all of the people who are currently using BuildVersion . semver to create dates . [CODESPLIT] def has_timestamp? ( version ) _ver , build_info = version . split ( \"+\" ) return false if build_info . nil? build_info . split ( \".\" ) . any? do | part | begin Time . strptime ( part , Omnibus :: BuildVersion :: TIMESTAMP_FORMAT ) true rescue ArgumentError false end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determines the build_version based on source_type output_method . [CODESPLIT] def construct_build_version ( version_source = nil ) case source_type when :git version = if version_source Omnibus :: BuildVersion . new ( version_source . project_dir ) else Omnibus :: BuildVersion . new end output = output_method || :semver self . build_version = version . send ( output ) when :version if version_source self . build_version = version_source . version else raise \"Please tell me the source to get the version from\" end else raise \"I don't know how to construct a build_version using source '#{source_type}'\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render an erb template to a String variable . [CODESPLIT] def render_template_content ( source , variables = { } ) template = ERB . new ( File . read ( source ) , nil , \"-\" ) struct = if variables . empty? Struct . new ( \"Empty\" ) else Struct . new ( variables . keys ) . new ( variables . values ) end template . result ( struct . instance_eval { binding } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render an erb template on disk at + source + . If the + : destination + option is given the file will be rendered at + : destination + otherwise the template is rendered next to + source + removing the erb extension of the template . [CODESPLIT] def render_template ( source , options = { } ) destination = options . delete ( :destination ) || source . chomp ( \".erb\" ) mode = options . delete ( :mode ) || 0644 variables = options . delete ( :variables ) || { } log . info ( log_key ) { \"Rendering `#{source}' to `#{destination}'\" } unless options . empty? raise ArgumentError , \"Unknown option(s): #{options.keys.map(&:inspect).join(', ')}\" end # String value returned from #render_template_content result = render_template_content ( source , variables ) File . open ( destination , \"w\" , mode ) do | file | file . write ( result ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Print a deprecation warning . This actually outputs to + WARN + but is prefixed with the string DEPRECATED first . [CODESPLIT] def deprecated ( progname , & block ) meta = Proc . new { \"DEPRECATED: #{yield}\" } add ( LEVELS . index ( \"WARN\" ) , progname , meta ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a message to the logger with the given severity and progname . [CODESPLIT] def add ( severity , progname , & block ) return true if io . nil? || severity < level message = format_message ( severity , progname , yield ) MUTEX . synchronize { io . write ( message ) } true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Idempotently create the required directories for building / downloading . Fetchers should call this method before performing any operations that manipulate the filesystem . [CODESPLIT] def create_required_directories [ Config . cache_dir , Config . source_dir , build_dir , project_dir , ] . each do | directory | FileUtils . mkdir_p ( directory ) unless File . directory? ( directory ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fetch any new files by copying them to the + project_dir + . [CODESPLIT] def fetch log . info ( log_key ) { \"Copying from `#{source_path}'\" } create_required_directories FileSyncer . sync ( source_path , project_dir , source_options ) # Reset target shasum on every fetch @target_shasum = nil target_shasum end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new builder object for evaluation . [CODESPLIT] def command ( command , options = { } ) warn_for_shell_commands ( command ) build_commands << BuildCommand . new ( \"Execute: `#{command}'\" ) do shellout! ( command , options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given make command . When present this method will prefer the use of + gmake + over + make + . If applicable this method will also set the MAKE = gmake environment variable when gmake is to be preferred . [CODESPLIT] def make ( * args ) options = args . last . is_a? ( Hash ) ? args . pop : { } make = options . delete ( :bin ) || # Prefer gmake on non-windows environments. if ! windows? && Omnibus . which ( \"gmake\" ) env = options . delete ( :env ) || { } env = { \"MAKE\" => \"gmake\" } . merge ( env ) options [ :env ] = env \"gmake\" else \"make\" end options [ :in_msys_bash ] = true make_cmd = ( [ make ] + args ) . join ( \" \" ) . strip command ( make_cmd , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run a prexisting . / configure script that was generated by autotools . On windows this will run configure within an msys bash shell with the given arguments . -- build is also set on your behalf based on windows_arch . A default prefix of # { install_bin } / embedded is appended . It is important to set -- build rather than -- host because by default -- build also sets -- host but it doesn t trigger cross - compilation mode in most configure scripts . Triggering this mode can confuse certain software projects like Ruby which depend on the build platform in its mkmf scripts . [CODESPLIT] def configure ( * args ) options = args . last . is_a? ( Hash ) ? args . pop : { } configure = options . delete ( :bin ) || \"./configure\" configure_cmd = [ configure ] # Pass the host platform as well. Different versions of config.guess # arrive at differently terrible wild ass guesses for what MSYSTEM=MINGW64 # means. This can be anything from x86_64-pc-mingw64 to i686-pc-mingw32 # which doesn't even make any sense... if windows? platform = windows_arch_i386? ? \"i686-w64-mingw32\" : \"x86_64-w64-mingw32\" configure_cmd << \"--build=#{platform}\" end # Accept a prefix override if provided. Can be set to '' to suppress # this functionality. prefix = options . delete ( :prefix ) || \"#{install_dir}/embedded\" configure_cmd << \"--prefix=#{prefix}\" if prefix && prefix != \"\" configure_cmd . concat args configure_cmd = configure_cmd . join ( \" \" ) . strip options [ :in_msys_bash ] = true command ( configure_cmd , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Apply the patch by the given name . This method will search all possible locations for a patch ( such as { Config#software_gems } ) . [CODESPLIT] def patch ( options = { } ) source = options . delete ( :source ) plevel = options . delete ( :plevel ) || 1 target = options . delete ( :target ) locations , patch_path = find_file ( \"config/patches\" , source ) unless patch_path raise MissingPatch . new ( source , locations ) end # Using absolute paths to the patch when invoking patch from within msys # is going to end is tears and table-flips. Use relative paths instead. # It's windows - we don't reasonably expect symlinks to show up any-time # soon and if you're using junction points, you're on your own. clean_patch_path = patch_path if windows? clean_patch_path = Pathname . new ( patch_path ) . relative_path_from ( Pathname . new ( software . project_dir ) ) . to_s end if target patch_cmd = \"cat #{clean_patch_path} | patch -p#{plevel} #{target}\" else patch_cmd = \"patch -p#{plevel} -i #{clean_patch_path}\" end patches << patch_path options [ :in_msys_bash ] = true build_commands << BuildCommand . new ( \"Apply patch `#{source}'\" ) do shellout! ( patch_cmd , options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given appbundler command against the embedded Ruby s appbundler . This command assumes the + appbundle + gem is installed and in the embedded Ruby . You should add a dependency on the + appbundler + software definition if you want to use this command . [CODESPLIT] def appbundle ( software_name , lockdir : nil , gem : nil , without : nil , extra_bin_files : nil , ** options ) build_commands << BuildCommand . new ( \"appbundle `#{software_name}'\" ) do bin_dir = \"#{install_dir}/bin\" appbundler_bin = embedded_bin ( \"appbundler\" ) lockdir ||= begin app_software = project . softwares . find do | p | p . name == software_name end if app_software . nil? raise \"could not find software definition for #{software_name}, add a dependency to it, or pass a lockdir argument to appbundle command.\" end app_software . project_dir end command = [ appbundler_bin , \"'#{lockdir}'\" , \"'#{bin_dir}'\" ] # This option is almost entirely for support of ChefDK and enables transitive gemfile lock construction in order # to be able to decouple the dev gems for all the different components of ChefDK.  AKA:  don't use it outside of # ChefDK.  You should also explicitly specify the lockdir when going down this road. command << [ \"'#{gem}'\" ] if gem # FIXME: appbundler lacks support for this argument when not also specifying the gem (2-arg appbundling lacks support) # (if you really need this bug fixed, though, fix it in appbundler, don't try using the 3-arg version to try to # get `--without` support, you will likely wind up going down a sad path). command << [ \"--without\" , without . join ( \",\" ) ] unless without . nil? command << [ \"--extra-bin-files\" , extra_bin_files . join ( \",\" ) ] unless extra_bin_files . nil? || extra_bin_files . empty? # Ensure the main bin dir exists FileUtils . mkdir_p ( bin_dir ) shellout! ( command . join ( \" \" ) , options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given Rake command against the embedded Ruby s rake . This command assumes the + rake + gem has been installed . [CODESPLIT] def rake ( command , options = { } ) build_commands << BuildCommand . new ( \"rake `#{command}'\" ) do bin = embedded_bin ( \"rake\" ) shellout! ( \"#{bin} #{command}\" , options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the erb template by the given name . This method will search all possible locations for an erb template ( such as { Config#software_gems } ) . [CODESPLIT] def erb ( options = { } ) source = options . delete ( :source ) dest = options . delete ( :dest ) mode = options . delete ( :mode ) || 0644 vars = options . delete ( :vars ) || { } raise \"Missing required option `:source'!\" unless source raise \"Missing required option `:dest'!\" unless dest locations , source_path = find_file ( \"config/templates\" , source ) unless source_path raise MissingTemplate . new ( source , locations ) end erbs << source_path block \"Render erb `#{source}'\" do render_template ( source_path , destination : dest , mode : mode , variables : vars ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!endgroup -------------------------------------------------- [CODESPLIT] def mkdir ( directory , options = { } ) build_commands << BuildCommand . new ( \"mkdir `#{directory}'\" ) do Dir . chdir ( software . project_dir ) do FileUtils . mkdir_p ( directory , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Touch the given filepath at runtime . This method will also ensure the containing directory exists first . [CODESPLIT] def touch ( file , options = { } ) build_commands << BuildCommand . new ( \"touch `#{file}'\" ) do Dir . chdir ( software . project_dir ) do parent = File . dirname ( file ) FileUtils . mkdir_p ( parent ) unless File . directory? ( parent ) FileUtils . touch ( file , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete the given file or directory on the system . This method uses the equivalent of + rm - rf + so you may pass in a specific file or a glob of files . [CODESPLIT] def delete ( path , options = { } ) build_commands << BuildCommand . new ( \"delete `#{path}'\" ) do Dir . chdir ( software . project_dir ) do FileSyncer . glob ( path ) . each do | file | FileUtils . rm_rf ( file , options ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Strip symbols from the given file or directory on the system . This method uses find and passes the matched files to strip through xargs ignoring errors . So one may pass in a specific file / directory or a glob of files . [CODESPLIT] def strip ( path ) regexp_ends = \".*(\" + IGNORED_ENDINGS . map { | e | e . gsub ( / \\. / , '\\.' ) } . join ( \"|\" ) + \")$\" regexp_patterns = IGNORED_PATTERNS . map { | e | \".*\" + e . gsub ( / \\/ / , '\\/' ) + \".*\" } . join ( \"|\" ) regexp = regexp_ends + \"|\" + regexp_patterns # Do not actually care if strip runs on non-strippable file, as its a no-op.  Hence the `|| true` appended. # Do want to avoid stripping files unneccessarily so as not to slow down build process. find_command = \"find #{path}/ -type f -regextype posix-extended ! -regex \\\"#{regexp}\\\" | xargs strip || true\" options = { in_msys_bash : true } command ( find_command , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy the given source to the destination . This method accepts a single file or a file pattern to match . [CODESPLIT] def copy ( source , destination , options = { } ) command = \"copy `#{source}' to `#{destination}'\" build_commands << BuildCommand . new ( command ) do Dir . chdir ( software . project_dir ) do files = FileSyncer . glob ( source ) if files . empty? log . warn ( log_key ) { \"no matched files for glob #{command}\" } else files . each do | file | FileUtils . cp_r ( file , destination , options ) end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "( see FileSyncer . sync ) [CODESPLIT] def sync ( source , destination , options = { } ) build_commands << BuildCommand . new ( \"sync `#{source}' to `#{destination}'\" ) do Dir . chdir ( software . project_dir ) do FileSyncer . sync ( source , destination , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helper method to update config_guess in the software s source directory . You should add a dependency on the + config_guess + software definition if you want to use this command . [CODESPLIT] def update_config_guess ( target : \".\" , install : [ :config_guess , :config_sub ] ) build_commands << BuildCommand . new ( \"update_config_guess `target: #{target} install: #{install.inspect}'\" ) do config_guess_dir = \"#{install_dir}/embedded/lib/config_guess\" %w{ config.guess config.sub } . each do | c | unless File . exist? ( File . join ( config_guess_dir , c ) ) raise \"Can not find #{c}. Make sure you add a dependency on 'config_guess' in your software definition\" end end destination = File . join ( software . project_dir , target ) FileUtils . mkdir_p ( destination ) FileUtils . cp_r ( \"#{config_guess_dir}/config.guess\" , destination ) if install . include? :config_guess FileUtils . cp_r ( \"#{config_guess_dir}/config.sub\" , destination ) if install . include? :config_sub end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!endgroup -------------------------------------------------- [CODESPLIT] def build log . info ( log_key ) { \"Starting build\" } shasum # ensure shashum is calculated before build since the build can alter the shasum log . internal ( log_key ) { \"Cached builder checksum before build: #{shasum}\" } if software . overridden? log . info ( log_key ) do \"Version overridden from #{software.default_version || \"n/a\"} to \" \"#{software.version}\" end end measure ( \"Build #{software.name}\" ) do build_commands . each do | command | execute ( command ) end end log . info ( log_key ) { \"Finished build\" } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The shasum for this builder object . The shasum is calculated using the following : [CODESPLIT] def shasum @shasum ||= begin digest = Digest :: SHA256 . new build_commands . each do | build_command | update_with_string ( digest , build_command . description ) end patches . each do | patch_path | update_with_file_contents ( digest , patch_path ) end erbs . each do | erb_path | update_with_file_contents ( digest , erb_path ) end digest . hexdigest end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is a helper method that wraps { Util#shellout! } for the purposes of setting the + : cwd + value . [CODESPLIT] def shellout! ( command_string , options = { } ) # Make sure the PWD is set to the correct directory # Also make a clone of options so that we can mangle it safely below. options = { cwd : software . project_dir } . merge ( options ) # Set the log level to :info so users will see build commands options [ :log_level ] ||= :info # Set the live stream to :debug so users will see build output options [ :live_stream ] ||= log . live_stream ( :debug ) # Use Util's shellout super ( command_string , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given block with ( n ) reties defined by { Config#build_retries } . This method will only retry for the following exceptions : [CODESPLIT] def with_retries ( & block ) tries = Config . build_retries delay = 5 exceptions = [ CommandFailed , CommandTimeout ] begin yield rescue exceptions => e if tries <= 0 raise e else delay *= 2 log . warn ( log_key ) do label = \"#{(Config.build_retries - tries) + 1}/#{Config.build_retries}\" \"[#{label}] Failed to execute command. Retrying in #{delay} seconds...\" end sleep ( delay ) tries -= 1 retry end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the given command removing any Ruby - specific environment variables . This is an enhanced version of + Bundler . with_clean_env + which only removes Bundler - specific values . We need to remove all values specifically : [CODESPLIT] def with_clean_env ( & block ) original = ENV . to_hash ENV . delete ( \"_ORIGINAL_GEM_PATH\" ) ENV . delete_if { | k , _ | k . start_with? ( \"BUNDLER_\" ) } ENV . delete_if { | k , _ | k . start_with? ( \"BUNDLE_\" ) } ENV . delete_if { | k , _ | k . start_with? ( \"GEM_\" ) } ENV . delete_if { | k , _ | k . start_with? ( \"RUBY\" ) } yield ensure ENV . replace ( original . to_hash ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find a file amonst all local files remote local files and { Config#software_gems } . [CODESPLIT] def find_file ( path , source ) # Search for patches just like we search for software candidate_paths = Omnibus . possible_paths_for ( path ) . map do | directory | File . join ( directory , software . name , source ) end file = candidate_paths . find { | path | File . exist? ( path ) } [ candidate_paths , file ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inspect the given command and warn if the command looks like it is a shell command that has a DSL method . ( like + command cp + versus + copy + ) . [CODESPLIT] def warn_for_shell_commands ( command ) case command when / /i log . warn ( log_key ) { \"Detected command `cp'. Consider using the `copy' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `rubocopy'. Consider using the `sync' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `mv'. Consider using the `move' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `rm'. Consider using the `delete' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `remove'. Consider using the `delete' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `rsync'. Consider using the `sync' DSL method.\" } when / /i log . warn ( log_key ) { \"Detected command `strip'. Consider using the `strip' DSL method.\" } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!endgroup -------------------------------------------------- [CODESPLIT] def run! # Ensure the package directory exists create_directory ( Config . package_dir ) measure ( \"Packaging time\" ) do # Run the setup and build sequences instance_eval ( self . class . setup ) if self . class . setup instance_eval ( self . class . build ) if self . class . build # Render the metadata Metadata . generate ( package_path , project ) # Ensure the temporary directory is removed at the end of a successful # run. Without removal, successful builds will \"leak\" in /tmp and cause # increased disk usage. # # Instead of having this as an +ensure+ block, failed builds will persist # this directory so developers can go poke around and figure out why the # build failed. remove_directory ( staging_dir ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!group Resource methods -------------------------------------------------- [CODESPLIT] def resource_path ( name ) local = File . join ( resources_path , name ) if File . exist? ( local ) log . info ( log_key ) { \"Using local resource `#{name}' from `#{local}'\" } local else log . debug ( log_key ) { \"Using vendored resource `#{name}'\" } Omnibus . source_root . join ( \"resources/#{id}/#{name}\" ) . to_s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!group DSL methods -------------------------------------------------- [CODESPLIT] def compression_level ( val = NULL ) if null? ( val ) @compression_level || Zlib :: BEST_COMPRESSION else unless val . is_a? ( Integer ) raise InvalidValue . new ( :compression_level , \"be an Integer\" ) end unless val . between? ( 1 , 9 ) raise InvalidValue . new ( :compression_level , \"be between 1-9\" ) end @compression_level = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the tar . gz to disk reading in 1024 bytes at a time to reduce memory usage . [CODESPLIT] def write_tgz # Grab the contents of the gzipped tarball for reading contents = gzipped_tarball # Write the .tar.gz into the staging directory File . open ( \"#{staging_dir}/#{package_name}\" , \"wb\" ) do | tgz | while chunk = contents . read ( 1024 ) tgz . write ( chunk ) end end # Copy the .tar.gz into the package directory FileSyncer . glob ( \"#{staging_dir}/*.tar.gz\" ) . each do | tgz | copy_file ( tgz , Config . package_dir ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create an in - memory tarball from the given packager . [CODESPLIT] def tarball tarfile = StringIO . new ( \"\" ) Gem :: Package :: TarWriter . new ( tarfile ) do | tar | path = \"#{staging_dir}/#{packager.package_name}\" name = packager . package_name mode = File . stat ( path ) . mode tar . add_file ( name , mode ) do | tf | File . open ( path , \"rb\" ) do | file | tf . write ( file . read ) end end end tarfile . rewind tarfile end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create the gzipped tarball . See { #tarball } for how the tarball is constructed . This method uses maximum gzip compression unless the user specifies a different compression level . [CODESPLIT] def gzipped_tarball gz = StringIO . new ( \"\" ) z = Zlib :: GzipWriter . new ( gz , compression_level ) z . write ( tarball . string ) z . close # z was closed to write the gzip footer, so # now we need a new StringIO StringIO . new ( gz . string ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Clean the project directory if it exists and actually extract the downloaded file . [CODESPLIT] def clean needs_cleaning = File . exist? ( project_dir ) if needs_cleaning log . info ( log_key ) { \"Cleaning project directory `#{project_dir}'\" } FileUtils . rm_rf ( project_dir ) end create_required_directories deploy needs_cleaning end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The path on disk to the downloaded asset . The filename is defined by + source : cached_name + . If ommited then it comes from the software s + source : url + value [CODESPLIT] def downloaded_file filename = source [ :cached_name ] if source [ :cached_name ] filename ||= File . basename ( source [ :url ] , \"?*\" ) File . join ( Config . cache_dir , filename ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Download the given file using Ruby s + OpenURI + implementation . This method may emit warnings as defined in software definitions using the + : warning + key . [CODESPLIT] def download log . warn ( log_key ) { source [ :warning ] } if source . key? ( :warning ) options = { } if source [ :unsafe ] log . warn ( log_key ) { \"Permitting unsafe redirects!\" } options [ :allow_unsafe_redirects ] = true end # Set the cookie if one was given options [ \"Cookie\" ] = source [ :cookie ] if source [ :cookie ] options [ \"Authorization\" ] = source [ :authorization ] if source [ :authorization ] download_file! ( download_url , downloaded_file , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extract the downloaded file using the magical logic based off of the ending file extension . In the rare event the file cannot be extracted it is copied over as a raw file . [CODESPLIT] def deploy if downloaded_file . end_with? ( ALL_EXTENSIONS ) log . info ( log_key ) { \"Extracting `#{safe_downloaded_file}' to `#{safe_project_dir}'\" } extract else log . info ( log_key ) { \"`#{safe_downloaded_file}' is not an archive - copying to `#{safe_project_dir}'\" } if File . directory? ( downloaded_file ) # If the file itself was a directory, copy the whole thing over. This # seems unlikely, because I do not think it is a possible to download # a folder, but better safe than sorry. FileUtils . cp_r ( \"#{downloaded_file}/.\" , project_dir ) else # In the more likely case that we got a \"regular\" file, we want that # file to live **inside** the project directory. project_dir should already # exist due to create_required_directories FileUtils . cp ( downloaded_file , project_dir ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extracts the downloaded archive file into project_dir . [CODESPLIT] def extract # Only used by tar compression_switch = \"\" compression_switch = \"z\" if downloaded_file . end_with? ( \"gz\" ) compression_switch = \"--lzma -\" if downloaded_file . end_with? ( \"lzma\" ) compression_switch = \"j\" if downloaded_file . end_with? ( \"bz2\" ) compression_switch = \"J\" if downloaded_file . end_with? ( \"xz\" ) if Ohai [ \"platform\" ] == \"windows\" if downloaded_file . end_with? ( TAR_EXTENSIONS ) && source [ :extract ] != :seven_zip returns = [ 0 ] returns << 1 if source [ :extract ] == :lax_tar shellout! ( \"tar #{compression_switch}xf #{safe_downloaded_file} -C#{safe_project_dir}\" , returns : returns ) elsif downloaded_file . end_with? ( COMPRESSED_TAR_EXTENSIONS ) Dir . mktmpdir do | temp_dir | log . debug ( log_key ) { \"Temporarily extracting `#{safe_downloaded_file}' to `#{temp_dir}'\" } shellout! ( \"7z.exe x #{safe_downloaded_file} -o#{windows_safe_path(temp_dir)} -r -y\" ) fname = File . basename ( downloaded_file , File . extname ( downloaded_file ) ) fname << \".tar\" if downloaded_file . end_with? ( \"tgz\" , \"txz\" ) next_file = windows_safe_path ( File . join ( temp_dir , fname ) ) log . debug ( log_key ) { \"Temporarily extracting `#{next_file}' to `#{safe_project_dir}'\" } shellout! ( \"7z.exe x #{next_file} -o#{safe_project_dir} -r -y\" ) end else shellout! ( \"7z.exe x #{safe_downloaded_file} -o#{safe_project_dir} -r -y\" ) end elsif downloaded_file . end_with? ( \".7z\" ) shellout! ( \"7z x #{safe_downloaded_file} -o#{safe_project_dir} -r -y\" ) elsif downloaded_file . end_with? ( \".zip\" ) shellout! ( \"unzip #{safe_downloaded_file} -d #{safe_project_dir}\" ) else shellout! ( \"#{tar} #{compression_switch}xf #{safe_downloaded_file} -C#{safe_project_dir}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The digest type defined in the software definition [CODESPLIT] def digest_type DIGESTS . each do | digest | return digest if source . key? digest end raise ChecksumMissing . new ( self ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Verify the downloaded file has the correct checksum . [CODESPLIT] def verify_checksum! log . info ( log_key ) { \"Verifying checksum\" } expected = checksum actual = digest ( downloaded_file , digest_type ) if expected != actual raise ChecksumMismatch . new ( self , expected , actual ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the signing certificate name [CODESPLIT] def signing_identity ( thumbprint = NULL , params = NULL ) unless null? ( thumbprint ) @signing_identity = { } unless thumbprint . is_a? ( String ) raise InvalidValue . new ( :signing_identity , \"be a String\" ) end @signing_identity [ :thumbprint ] = thumbprint if ! null? ( params ) unless params . is_a? ( Hash ) raise InvalidValue . new ( :params , \"be a Hash\" ) end valid_keys = [ :store , :timestamp_servers , :machine_store , :algorithm ] invalid_keys = params . keys - valid_keys unless invalid_keys . empty? raise InvalidValue . new ( :params , \"contain keys from [#{valid_keys.join(', ')}]. \" \"Found invalid keys [#{invalid_keys.join(', ')}]\" ) end if ! params [ :machine_store ] . nil? && ! ( params [ :machine_store ] . is_a? ( TrueClass ) || params [ :machine_store ] . is_a? ( FalseClass ) ) raise InvalidValue . new ( :params , \"contain key :machine_store of type TrueClass or FalseClass\" ) end else params = { } end @signing_identity [ :store ] = params [ :store ] || \"My\" @signing_identity [ :algorithm ] = params [ :algorithm ] || \"SHA256\" servers = params [ :timestamp_servers ] || DEFAULT_TIMESTAMP_SERVERS @signing_identity [ :timestamp_servers ] = [ servers ] . flatten @signing_identity [ :machine_store ] = params [ :machine_store ] || false end @signing_identity end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates through available timestamp servers and tries to sign the file with with each server stopping after the first to succeed . If none succeed an exception is raised . [CODESPLIT] def sign_package ( package_file ) success = false timestamp_servers . each do | ts | success = try_sign ( package_file , ts ) break if success end raise FailedToSignWindowsPackage . new if ! success end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the certificate subject of the signing identity [CODESPLIT] def certificate_subject return \"CN=#{project.package_name}\" unless signing_identity store = machine_store? ? \"LocalMachine\" : \"CurrentUser\" cmd = Array . new . tap do | arr | arr << \"powershell.exe\" arr << \"-ExecutionPolicy Bypass\" arr << \"-NoProfile\" arr << \"-Command (Get-Item Cert:/#{store}/#{cert_store_name}/#{thumbprint}).Subject\" end . join ( \" \" ) shellout! ( cmd ) . stdout . strip end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse and return the version from the { Project#build_version } . [CODESPLIT] def windows_package_version major , minor , patch = project . build_version . split ( / / ) [ major , minor , patch , project . build_iteration ] . join ( \".\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new software object . [CODESPLIT] def manifest_entry @manifest_entry ||= if manifest log . info ( log_key ) { \"Using user-supplied manifest entry for #{name}\" } manifest . entry_for ( name ) else log . info ( log_key ) { \"Resolving manifest entry for #{name}\" } to_manifest_entry end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or retrieve the source for the software . [CODESPLIT] def source ( val = NULL ) unless null? ( val ) unless val . is_a? ( Hash ) raise InvalidValue . new ( :source , \"be a kind of `Hash', but was `#{val.class.inspect}'\" ) end val = canonicalize_source ( val ) extra_keys = val . keys - [ :git , :file , :path , :url , # fetcher types :md5 , :sha1 , :sha256 , :sha512 , # hash type - common to all fetchers :cookie , :warning , :unsafe , :extract , :cached_name , :authorization , # used by net_fetcher :options , # used by path_fetcher :submodules # used by git_fetcher ] unless extra_keys . empty? raise InvalidValue . new ( :source , \"only include valid keys. Invalid keys: #{extra_keys.inspect}\" ) end duplicate_keys = val . keys & [ :git , :file , :path , :url ] unless duplicate_keys . size < 2 raise InvalidValue . new ( :source , \"not include duplicate keys. Duplicate keys: #{duplicate_keys.inspect}\" ) end @source ||= { } @source . merge! ( val ) end override = canonicalize_source ( overrides [ :source ] ) apply_overrides ( :source , override ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Evaluate a block only if the version matches . [CODESPLIT] def version ( val = NULL , & block ) final_version = apply_overrides ( :version ) if block_given? if val . equal? ( NULL ) raise InvalidValue . new ( :version , \"pass a block when given a version argument\" ) else if val == final_version # # Unfortunately we need to make a specific logic here for license files. # We support multiple calls `license_file` and we support overriding the # license files inside a version block. We can not differentiate whether # `license_file` is being called from a version block or not. So we need # to check if the license files are being overridden during the call to # block. # # If so we use the new set, otherwise we restore the old license files. # current_license_files = @license_files @license_files = [ ] yield new_license_files = @license_files if new_license_files . empty? @license_files = current_license_files end end end end return if final_version . nil? begin Chef :: Sugar :: Constraints :: Version . new ( final_version ) rescue ArgumentError log . warn ( log_key ) do \"Version #{final_version} for software #{name} was not parseable. \" \"Comparison methods such as #satisfies? will not be available for this version.\" end final_version end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a file to the healthcheck whitelist . [CODESPLIT] def whitelist_file ( file ) file = Regexp . new ( file ) unless file . kind_of? ( Regexp ) whitelist_files << file whitelist_files . dup end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The path to the downloaded file from a NetFetcher . [CODESPLIT] def project_file if fetcher && fetcher . is_a? ( NetFetcher ) log . deprecated ( log_key ) do \"project_file (DSL). This is a property of the NetFetcher and will \" \"not be publically exposed in the next major release. In general, \" \"you should not be using this method in your software definitions \" \"as it is an internal implementation detail of the NetFetcher. If \" \"you disagree with this statement, you should open an issue on the \" \"Omnibus repository on GitHub an explain your use case. For now, \" \"I will return the path to the downloaded file on disk, but please \" \"rethink the problem you are trying to solve :).\" end fetcher . downloaded_file else log . warn ( log_key ) do \"Cannot retrieve a `project_file' for software `#{name}'. This \" \"attribute is actually an internal representation that is unique \" \"to the NetFetcher class and requires the use of a `source' \" \"attribute that is declared using a `:url' key. For backwards-\" \"compatability, I will return `nil', but this is most likely not \" \"your desired behavior.\" end nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add standard compiler flags to the environment hash to produce omnibus binaries ( correct RPATH etc ) . [CODESPLIT] def with_standard_compiler_flags ( env = { } , opts = { } ) env ||= { } opts ||= { } compiler_flags = case Ohai [ \"platform\" ] when \"aix\" { \"CC\" => \"xlc_r -q64\" , \"CXX\" => \"xlC_r -q64\" , \"CFLAGS\" => \"-q64 -I#{install_dir}/embedded/include -D_LARGE_FILES -O\" , \"LDFLAGS\" => \"-q64 -L#{install_dir}/embedded/lib -Wl,-blibpath:#{install_dir}/embedded/lib:/usr/lib:/lib\" , \"LD\" => \"ld -b64\" , \"OBJECT_MODE\" => \"64\" , \"ARFLAGS\" => \"-X64 cru\" , } when \"solaris2\" if platform_version . satisfies? ( \"<= 5.10\" ) solaris_flags = { # this override is due to a bug in libtool documented here: # http://lists.gnu.org/archive/html/bug-libtool/2005-10/msg00004.html \"CC\" => \"gcc -static-libgcc\" , \"LDFLAGS\" => \"-R#{install_dir}/embedded/lib -L#{install_dir}/embedded/lib -static-libgcc\" , \"CFLAGS\" => \"-I#{install_dir}/embedded/include -O2\" , } elsif platform_version . satisfies? ( \">= 5.11\" ) solaris_flags = { \"CC\" => \"gcc -m64 -static-libgcc\" , \"LDFLAGS\" => \"-Wl,-rpath,#{install_dir}/embedded/lib -L#{install_dir}/embedded/lib -static-libgcc\" , \"CFLAGS\" => \"-I#{install_dir}/embedded/include -O2\" , } end solaris_flags when \"freebsd\" { \"CC\" => \"clang\" , \"CXX\" => \"clang++\" , \"LDFLAGS\" => \"-L#{install_dir}/embedded/lib\" , \"CFLAGS\" => \"-I#{install_dir}/embedded/include -O2\" , } when \"suse\" suse_flags = { \"LDFLAGS\" => \"-Wl,-rpath,#{install_dir}/embedded/lib -L#{install_dir}/embedded/lib\" , \"CFLAGS\" => \"-I#{install_dir}/embedded/include -O2\" , } # Enable gcc version 4.8 if it is available if which ( \"gcc-4.8\" ) && platform_version . satisfies? ( \"< 12\" ) suse_flags [ \"CC\" ] = \"gcc-4.8\" suse_flags [ \"CXX\" ] = \"g++-4.8\" end suse_flags when \"windows\" arch_flag = windows_arch_i386? ? \"-m32\" : \"-m64\" opt_flag = windows_arch_i386? ? \"-march=i686\" : \"-march=x86-64\" { \"LDFLAGS\" => \"-L#{install_dir}/embedded/lib #{arch_flag} -fno-lto\" , # We do not wish to enable SSE even though we target i686 because # of a stack alignment issue with some libraries. We have not # exactly ascertained the cause but some compiled library/binary # violates gcc's assumption that the stack is going to be 16-byte # aligned which is just fine as long as one is pushing 32-bit # values from general purpose registers but stuff hits the fan as # soon as gcc emits aligned SSE xmm register spills which generate # GPEs and terminate the application very rudely with very little # to debug with. \"CFLAGS\" => \"-I#{install_dir}/embedded/include #{arch_flag} -O3 #{opt_flag}\" , } else { \"LDFLAGS\" => \"-Wl,-rpath,#{install_dir}/embedded/lib -L#{install_dir}/embedded/lib\" , \"CFLAGS\" => \"-I#{install_dir}/embedded/include -O2\" , } end # merge LD_RUN_PATH into the environment.  most unix distros will fall # back to this if there is no LDFLAGS passed to the linker that sets # the rpath.  the LDFLAGS -R or -Wl,-rpath will override this, but in # some cases software may drop our LDFLAGS or think it knows better # and edit them, and we *really* want the rpath setting and do know # better.  in that case LD_RUN_PATH will probably survive whatever # edits the configure script does extra_linker_flags = { \"LD_RUN_PATH\" => \"#{install_dir}/embedded/lib\" , } if solaris2? ld_options = \"-R#{install_dir}/embedded/lib\" if platform_version . satisfies? ( \"<= 5.10\" ) # in order to provide compatibility for earlier versions of libc on solaris 10, # we need to specify a mapfile that restricts the version of system libraries # used. See http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter5-1.html # for more information # use the mapfile if it exists, otherwise ignore it mapfile_path = File . expand_path ( Config . solaris_linker_mapfile , Config . project_root ) ld_options << \" -M #{mapfile_path}\" if File . exist? ( mapfile_path ) end # solaris linker can also use LD_OPTIONS, so we throw the kitchen sink against # the linker, to find every way to make it use our rpath. This is also required # to use the aforementioned mapfile. extra_linker_flags [ \"LD_OPTIONS\" ] = ld_options end env . merge ( compiler_flags ) . merge ( extra_linker_flags ) . # always want to favor pkg-config from embedded location to not hose # configure scripts which try to be too clever and ignore our explicit # CFLAGS and LDFLAGS in favor of pkg-config info merge ( { \"PKG_CONFIG_PATH\" => \"#{install_dir}/embedded/lib/pkgconfig\" } ) . # Set default values for CXXFLAGS and CPPFLAGS. merge ( \"CXXFLAGS\" => compiler_flags [ \"CFLAGS\" ] ) . merge ( \"CPPFLAGS\" => compiler_flags [ \"CFLAGS\" ] ) . merge ( \"OMNIBUS_INSTALL_DIR\" => install_dir ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A PATH variable format string representing the current PATH with the project s embedded / bin directory prepended . The correct path separator for the platform is used to join the paths . [CODESPLIT] def with_embedded_path ( env = { } ) paths = [ \"#{install_dir}/bin\" , \"#{install_dir}/embedded/bin\" ] path_value = prepend_path ( paths ) env . merge ( path_key => path_value ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A PATH variable format string representing the current PATH with the given path prepended . The correct path separator for the platform is used to join the paths . [CODESPLIT] def prepend_path ( * paths ) path_values = Array ( paths ) path_values << ENV [ path_key ] separator = File :: PATH_SEPARATOR || \":\" path_values . join ( separator ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!endgroup -------------------------------------------------- [CODESPLIT] def load_dependencies dependencies . each do | dependency | Software . load ( project , dependency , manifest ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The repo - level and project - level overrides for the software . [CODESPLIT] def overrides if null? ( @overrides ) # lazily initialized because we need the 'name' to be parsed first @overrides = { } @overrides = project . overrides [ name . to_sym ] . dup if project . overrides [ name . to_sym ] end @overrides end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the version to be used in cache . [CODESPLIT] def version_for_cache @version_for_cache ||= if fetcher . version_for_cache fetcher . version_for_cache elsif version version else log . warn ( log_key ) do \"No version given! This is probably a bad thing. I am going to \" \"assume the version `0.0.0', but that is most certainly not your \" \"desired behavior. If git caching seems off, this is probably why.\" end \"0.0.0\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The fetcher for this software [CODESPLIT] def fetcher @fetcher ||= if source_type == :url && File . basename ( source [ :url ] , \"?*\" ) . end_with? ( NetFetcher :: ALL_EXTENSIONS ) Fetcher . fetcher_class_for_source ( source ) . new ( manifest_entry , fetch_dir , build_dir ) else Fetcher . fetcher_class_for_source ( source ) . new ( manifest_entry , project_dir , build_dir ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build the software package . If git caching is turned on ( see { Config#use_git_caching } ) the build is restored according to the documented restoration procedure in the git cache . If the build cannot be restored ( if the tag does not exist ) the actual build steps are executed . [CODESPLIT] def build_me ( build_wrappers = [ ] ) if Config . use_git_caching if project . dirty? log . info ( log_key ) do \"Building because `#{project.culprit.name}' dirtied the cache\" end execute_build ( build_wrappers ) elsif git_cache . restore log . info ( log_key ) { \"Restored from cache\" } else log . info ( log_key ) { \"Could not restore from cache\" } execute_build ( build_wrappers ) project . dirty! ( self ) end else log . debug ( log_key ) { \"Forcing build because git caching is off\" } execute_build ( build_wrappers ) end project . build_version_dsl . resolve ( self ) true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The unique SHA256 for this sofware definition . [CODESPLIT] def shasum @shasum ||= begin digest = Digest :: SHA256 . new update_with_string ( digest , project . shasum ) update_with_string ( digest , builder . shasum ) update_with_string ( digest , name ) update_with_string ( digest , version_for_cache ) update_with_string ( digest , FFI_Yajl :: Encoder . encode ( overrides ) ) if filepath && File . exist? ( filepath ) update_with_file_contents ( digest , filepath ) else update_with_string ( digest , \"<DYNAMIC>\" ) end digest . hexdigest end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Apply overrides in the [CODESPLIT] def apply_overrides ( attr , override = overrides [ attr ] ) val = instance_variable_get ( :\" #{ attr } \" ) if val . is_a? ( Hash ) || override . is_a? ( Hash ) val ||= { } override ||= { } val . merge ( override ) else override || val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Transform github - > git in source [CODESPLIT] def canonicalize_source ( source ) if source . is_a? ( Hash ) && source [ :github ] source = source . dup source [ :git ] = \"https://github.com/#{source[:github]}.git\" source . delete ( :github ) end source end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Actually build this software executing the steps provided in the { #build } block and dirtying the cache . [CODESPLIT] def execute_build ( build_wrappers ) fetcher . clean build_wrappers . each { | wrapper | wrapper . execute_pre_build ( self ) } builder . build build_wrappers . each { | wrapper | wrapper . execute_post_build ( self ) } if Config . use_git_caching git_cache . incremental log . info ( log_key ) { \"Dirtied the cache\" } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a makeselfinst in the staging directory using the supplied ERB template . This file will be used to move the contents of the self - extracting archive into place following extraction . [CODESPLIT] def write_makeselfinst makeselfinst_staging_path = File . join ( staging_dir , \"makeselfinst\" ) render_template ( resource_path ( \"makeselfinst.erb\" ) , destination : makeselfinst_staging_path , variables : { install_dir : project . install_dir , } ) FileUtils . chmod ( 0755 , makeselfinst_staging_path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run the actual makeself command publishing the generated package . [CODESPLIT] def create_makeself_package log . info ( log_key ) { \"Creating makeself package\" } Dir . chdir ( staging_dir ) do shellout! <<-EOH . gsub ( / / , \"\" ) #{ makeself } \\\\ #{ makeself_header } \\\\ \\\\ #{ staging_dir } \\\\ #{ package_name } \\\\ #{ project . description } \\\\ EOH end FileSyncer . glob ( \"#{staging_dir}/*.sh\" ) . each do | makeself | copy_file ( makeself , Config . package_dir ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates the full path if it does not exist already . [CODESPLIT] def create_cache_path if File . directory? ( cache_path ) false else create_directory ( File . dirname ( cache_path ) ) git_cmd ( \"init -q\" ) # On windows, git is very picky about single vs double quotes git_cmd ( \"config --local user.name \\\"Omnibus Git Cache\\\"\" ) git_cmd ( \"config --local user.email \\\"omnibus@localhost\\\"\" ) true end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the tag for this cache entry . [CODESPLIT] def tag return @tag if @tag log . internal ( log_key ) { \"Calculating tag\" } # Accumulate an array of all the software projects that come before # the name and version we are tagging. So if you have # # build_order = [ 1, 2, 3, 4, 5 ] # # And we are tagging 3, you would get dep_list = [ 1, 2 ] dep_list = software . project . library . build_order . take_while do | dep | if dep . name == software . name && dep . version == software . version false else true end end log . internal ( log_key ) { \"dep_list: #{dep_list.map(&:name).inspect}\" } # This is the list of all the unqiue shasums of all the software build # dependencies, including the on currently being acted upon. shasums = [ dep_list . map ( :shasum ) , software . shasum ] . flatten suffix = Digest :: SHA256 . hexdigest ( shasums . join ( \"|\" ) ) @tag = \"#{software.name}-#{suffix}-#{SERIAL_NUMBER}\" log . internal ( log_key ) { \"tag: #{@tag}\" } @tag end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create an incremental install path cache for the software step [CODESPLIT] def incremental log . internal ( log_key ) { \"Performing incremental cache\" } create_cache_path remove_git_dirs git_cmd ( \"add -A -f\" ) begin git_cmd ( %Q{commit -q -m \"Backup of #{tag}\"} ) rescue CommandFailed => e raise unless e . message . include? ( \"nothing to commit\" ) end git_cmd ( %Q{tag -f \"#{tag}\"} ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Git caching will attempt to version embedded git directories partially versioning them . This causes failures on subsequent runs . This method will find git directories and remove them to prevent those errors . [CODESPLIT] def remove_git_dirs log . internal ( log_key ) { \"Removing git directories\" } Dir . glob ( \"#{install_dir}/**/{,.*}/config\" ) . reject do | path | REQUIRED_GIT_FILES . any? do | required_file | ! File . exist? ( File . join ( File . dirname ( path ) , required_file ) ) end end . each do | path | log . internal ( log_key ) { \"Removing git dir `#{path}'\" } FileUtils . rm_rf ( File . dirname ( path ) ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the manifest file into the staging directory . [CODESPLIT] def write_manifest_file render_template ( resource_path ( \"AppxManifest.xml.erb\" ) , destination : \"#{windows_safe_path(project.install_dir)}/AppxManifest.xml\" , variables : { name : project . package_name , friendly_name : project . friendly_name , version : windows_package_version , maintainer : project . maintainer , certificate_subject : certificate_subject . gsub ( '\"' , \"&quot;\" ) , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The proper platform - specific $PATH key . [CODESPLIT] def path_key # The ruby devkit needs ENV['Path'] set instead of ENV['PATH'] because # $WINDOWSRAGE, and if you don't set that your native gem compiles # will fail because the magic fixup it does to add the mingw compiler # stuff won't work. # # Turns out there is other build environments that only set ENV['PATH'] and if we # modify ENV['Path'] then it ignores that.  So, we scan ENV and returns the first # one that we find. # if windows? result = ENV . keys . grep ( / \\A \\Z /i ) case result . length when 0 raise \"The current omnibus environment has no PATH\" when 1 result . first else raise \"The current omnibus environment has multiple PATH/Path variables.\" end else \"PATH\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Shells out and runs + command + . [CODESPLIT] def shellout ( * args ) options = args . last . kind_of? ( Hash ) ? args . pop : { } options = SHELLOUT_OPTIONS . merge ( options ) command_string = args . join ( \" \" ) in_msys = options . delete ( :in_msys_bash ) && ENV [ \"MSYSTEM\" ] # Mixlib will handle escaping characters for cmd but our command might # contain '. For now, assume that won't happen because I don't know # whether this command is going to be played via cmd or through # ProcessCreate. command_string = \"bash -c \\'#{command_string}\\'\" if in_msys # Grab the log_level log_level = options . delete ( :log_level ) # Set the live stream if one was not given options [ :live_stream ] ||= log . live_stream ( :internal ) # Since Mixlib::ShellOut supports :environment and :env, we want to # standardize here if options [ :env ] options [ :environment ] = options . fetch ( :environment , { } ) . merge ( options [ :env ] ) end # Log any environment options given unless options [ :environment ] . empty? log . public_send ( log_level , log_key ) { \"Environment:\" } options [ :environment ] . sort . each do | key , value | log . public_send ( log_level , log_key ) { \"  #{key}=#{value.inspect}\" } end end # Log the actual command log . public_send ( log_level , log_key ) { \"$ #{command_string}\" } cmd = Mixlib :: ShellOut . new ( command_string , options ) cmd . environment [ \"HOME\" ] = \"/tmp\" unless ENV [ \"HOME\" ] cmd . run_command cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Similar to + shellout + method except it raises an exception if the command fails . [CODESPLIT] def shellout! ( * args ) cmd = shellout ( args ) cmd . error! cmd rescue Mixlib :: ShellOut :: ShellCommandFailed raise CommandFailed . new ( cmd ) rescue Mixlib :: ShellOut :: CommandTimeout raise CommandTimeout . new ( cmd ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retry the given block if a retriable exception is raised . Returns the value of the block call if successful . [CODESPLIT] def retry_block ( logstr , retried_exceptions = [ ] , retries = Omnibus :: Config . fetcher_retries , & block ) yield rescue Exception => e raise e unless retried_exceptions . any? { | eclass | e . is_a? ( eclass ) } if retries != 0 log . info ( log_key ) { \"Retrying failed #{logstr} due to #{e} (#{retries} retries left)...\" } retries -= 1 retry else log . error ( log_key ) { \"#{logstr} failed - #{e.class}!\" } raise end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert the given path to be appropiate for shelling out on Windows . [CODESPLIT] def windows_safe_path ( * pieces ) path = File . join ( pieces ) if File :: ALT_SEPARATOR path . gsub ( File :: SEPARATOR , File :: ALT_SEPARATOR ) else path end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert the given path to be appropriate for usage with the given compiler [CODESPLIT] def compiler_safe_path ( * pieces ) path = File . join ( pieces ) path = path . sub ( / \\/ / , \"/\\\\1/\" ) if ENV [ \"MSYSTEM\" ] path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a directory at the given + path + . [CODESPLIT] def create_directory ( * paths ) path = File . join ( paths ) log . debug ( log_key ) { \"Creating directory `#{path}'\" } FileUtils . mkdir_p ( path ) path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove the directory at the given + path + . [CODESPLIT] def remove_directory ( * paths ) path = File . join ( paths ) log . debug ( log_key ) { \"Remove directory `#{path}'\" } FileUtils . rm_rf ( path ) path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy the + source + file to the + destination + . [CODESPLIT] def copy_file ( source , destination ) log . debug ( log_key ) { \"Copying `#{source}' to `#{destination}'\" } FileUtils . cp ( source , destination ) destination end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove the file at the given path . [CODESPLIT] def remove_file ( * paths ) path = File . join ( paths ) log . debug ( log_key ) { \"Removing file `#{path}'\" } FileUtils . rm_f ( path ) path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a file at the given path . If a block is given the contents of the block are written to the file . If the block is not given the file is simply touched . [CODESPLIT] def create_file ( * paths , & block ) path = File . join ( paths ) log . debug ( log_key ) { \"Creating file `#{path}'\" } FileUtils . mkdir_p ( File . dirname ( path ) ) if block File . open ( path , \"wb\" ) { | f | f . write ( yield ) } else FileUtils . touch ( path ) end path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a symlink from a to b [CODESPLIT] def create_link ( a , b ) log . debug ( log_key ) { \"Linking `#{a}' to `#{b}'\" } FileUtils . ln_s ( a , b ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Project ] project the project to create licenses for . [CODESPLIT] def prepare FileUtils . rm_rf ( output_dir ) FileUtils . mkdir_p ( output_dir ) FileUtils . touch ( output_dir_gitkeep_file ) FileUtils . rm_rf ( cache_dir ) FileUtils . mkdir_p ( cache_dir ) FileUtils . touch ( cache_dir_gitkeep_file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Callback that gets called by Software#build_me after the build is done . Invokes license copying for the given software . This ensures that licenses are copied before a git cache snapshot is taken so that the license files are correctly restored when a build is skipped due to a cache hit . [CODESPLIT] def execute_post_build ( software ) collect_licenses_for ( software ) unless software . skip_transitive_dependency_licensing collect_transitive_dependency_licenses_for ( software ) check_transitive_dependency_licensing_errors_for ( software ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inspects the licensing information for the project and the included software components . Logs the found issues to the log as warning . [CODESPLIT] def validate_license_info # First check the project licensing information # Check existence of licensing information if project . license == \"Unspecified\" licensing_warning ( \"Project '#{project.name}' does not contain licensing information.\" ) end # Check license file exists if project . license != \"Unspecified\" && project . license_file . nil? licensing_warning ( \"Project '#{project.name}' does not point to a license file.\" ) end # Check used license is a standard license if project . license != \"Unspecified\" && ! STANDARD_LICENSES . include? ( project . license ) licensing_info ( \"Project '#{project.name}' is using '#{project.license}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.\" ) end # Now let's check the licensing info for software components license_map . each do | software_name , license_info | # First check if the software specified a license if license_info [ :license ] == \"Unspecified\" licensing_warning ( \"Software '#{software_name}' does not contain licensing information.\" ) end # Check if the software specifies any license files if license_info [ :license ] != \"Unspecified\" && license_info [ :license_files ] . empty? licensing_warning ( \"Software '#{software_name}' does not point to any license files.\" ) end # Check if the software license is one of the standard licenses if license_info [ :license ] != \"Unspecified\" && ! STANDARD_LICENSES . include? ( license_info [ :license ] ) licensing_info ( \"Software '#{software_name}' uses license '#{license_info[:license]}' which is not one of the standard licenses identified in https://opensource.org/licenses/alphabetical. Consider using one of the standard licenses.\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates the top level license file for the project . Top level file is created at # { project . license_file_path } and contains the name of the project version of the project text of the license of the project and a summary of the licenses of the included software components . [CODESPLIT] def create_project_license_file File . open ( project . license_file_path , \"w\" ) do | f | f . puts \"#{project.name} #{project.build_version} license: \\\"#{project.license}\\\"\" f . puts \"\" f . puts project_license_content f . puts \"\" f . puts components_license_summary f . puts \"\" f . puts dependencies_license_summary end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Contents of the project s license [CODESPLIT] def project_license_content project . license_file . nil? ? \"\" : IO . read ( File . join ( Config . project_root , project . license_file ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Summary of the licenses included by the softwares of the project . It is in the form of : ... This product bundles python 2 . 7 . 9 which is available under a Python License . For details see : / opt / opscode / LICENSES / python - LICENSE ... [CODESPLIT] def components_license_summary out = \"\\n\\n\" license_map . keys . sort . each do | name | license = license_map [ name ] [ :license ] license_files = license_map [ name ] [ :license_files ] version = license_map [ name ] [ :version ] out << \"This product bundles #{name} #{version},\\n\" out << \"which is available under a \\\"#{license}\\\" License.\\n\" if ! license_files . empty? out << \"For details, see:\\n\" license_files . each do | license_file | out << \"#{license_package_location(name, license_file)}\\n\" end end out << \"\\n\" end out end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Summary of the licenses of the transitive dependencies of the project . It is in the form of : ... This product includes inifile 3 . 0 . 0 which is a ruby_bundler dependency of chef and which is available under a MIT License . For details see : / opt / opscode / LICENSES / ruby_bundler - inifile - 3 . 0 . 0 - README . md ... [CODESPLIT] def dependencies_license_summary out = \"\\n\\n\" dep_license_map . each do | dep_mgr_name , data | data . each do | dep_name , data | data . each do | dep_version , dep_data | projects = dep_data [ \"dependency_of\" ] . sort . map { | p | \"'#{p}'\" } . join ( \", \" ) files = dep_data [ \"license_files\" ] . map { | f | File . join ( output_dir , f ) } out << \"This product includes #{dep_name} #{dep_version}\\n\" out << \"which is a '#{dep_mgr_name}' dependency of #{projects},\\n\" out << \"and which is available under a '#{dep_data[\"license\"]}' License.\\n\" out << \"For details, see:\\n\" out << files . join ( \"\\n\" ) out << \"\\n\\n\" end end end out end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Map that collects information about the licenses of the softwares included in the project . [CODESPLIT] def license_map @license_map ||= begin map = { } project . library . each do | component | # Some of the components do not bundle any software but contain # some logic that we use during the build. These components are # covered under the project's license and they do not need specific # license files. next if component . license == :project_license map [ component . name ] = { license : component . license , license_files : component . license_files , version : component . version , project_dir : component . project_dir , } end map end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the location where the license file should reside in the package . License file is named as <project_name > - <license_file_name > and created under the output licenses directory . [CODESPLIT] def license_package_location ( component_name , where ) if local? ( where ) File . join ( output_dir , \"#{component_name}-#{File.split(where).last}\" ) else u = URI ( where ) File . join ( output_dir , \"#{component_name}-#{File.basename(u.path)}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "0 . Translate all transitive dependency licensing issues into omnibus warnings 1 . Parse all the licensing information for all software from cache_dir 2 . Merge and drop the duplicates 3 . Add these licenses to the main manifest to be merged with the main licensing information from software definitions . [CODESPLIT] def process_transitive_dependency_licensing_info Dir . glob ( \"#{cache_dir}/*/*-dependency-licenses.json\" ) . each do | license_manifest_path | license_manifest_data = FFI_Yajl :: Parser . parse ( File . read ( license_manifest_path ) ) project_name = license_manifest_data [ \"project_name\" ] dependency_license_dir = File . dirname ( license_manifest_path ) license_manifest_data [ \"dependency_managers\" ] . each do | dep_mgr_name , dependencies | dep_license_map [ dep_mgr_name ] ||= { } dependencies . each do | dependency | # Copy dependency files dependency [ \"license_files\" ] . each do | f | license_path = File . join ( dependency_license_dir , f ) output_path = File . join ( output_dir , f ) FileUtils . cp ( license_path , output_path ) end dep_name = dependency [ \"name\" ] dep_version = dependency [ \"version\" ] # If we already have this dependency we do not need to add it again. if dep_license_map [ dep_mgr_name ] [ dep_name ] && dep_license_map [ dep_mgr_name ] [ dep_name ] [ dep_version ] dep_license_map [ dep_mgr_name ] [ dep_name ] [ dep_version ] [ \"dependency_of\" ] << project_name else dep_license_map [ dep_mgr_name ] [ dep_name ] ||= { } dep_license_map [ dep_mgr_name ] [ dep_name ] [ dep_version ] = { \"license\" => dependency [ \"license\" ] , \"license_files\" => dependency [ \"license_files\" ] , \"dependency_of\" => [ project_name ] , } end end end end FileUtils . rm_rf ( cache_dir ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Uses license_scout to collect the licenses for transitive dependencies into # { output_dir } / license - cache / # { software . name } [CODESPLIT] def collect_transitive_dependency_licenses_for ( software ) # We collect the licenses of the transitive dependencies of this software # with LicenseScout. We place these files under # /opt/project-name/license-cache for them to be cached in git_cache. Once # the build completes we will process these license files but we need to # perform this step after build, before git_cache to be able to operate # correctly with the git_cache. collector = LicenseScout :: Collector . new ( software . name , software . project_dir , license_output_dir ( software ) , LicenseScout :: Options . new ( environment : software . with_embedded_path , ruby_bin : software . embedded_bin ( \"ruby\" ) , manual_licenses : software . dependency_licenses ) ) begin # We do not automatically collect dependency licensing information when # skip_transitive_dependency_licensing is set on the software. collector . run rescue LicenseScout :: Exceptions :: UnsupportedProjectType => e # Looks like this project is not supported by LicenseScout. Either the # language and the dependency manager used by the project is not # supported, or the software definition does not have any transitive # dependencies.  In the latter case software definition should set # 'skip_transitive_dependency_licensing' to 'true' to correct this # error. transitive_dependency_licensing_warning ( <<-EOH ) #{ software . name } \\\n \\\n \\\n \\\n EOH # If we got here, we need to fail now so we don't take a git # cache snapshot, or else the software build could be restored # from cache without fixing the license issue. raise_if_warnings_fatal! rescue LicenseScout :: Exceptions :: Error => e transitive_dependency_licensing_warning ( <<-EOH ) #{ software . name } \\\n #{ e } EOH # If we got here, we need to fail now so we don't take a git # cache snapshot, or else the software build could be restored # from cache without fixing the license issue. raise_if_warnings_fatal! rescue Exception => e # This catch all exception handling is here in order not to fail builds # until license_scout gets more stable. As we are adding support for more # and more dependency managers we discover unhandled edge cases which # requires us to have this. Remove this once license_scout is stable. transitive_dependency_licensing_warning ( <<-EOH ) #{ software . name } #{ e } EOH # If we got here, we need to fail now so we don't take a git # cache snapshot, or else the software build could be restored # from cache without fixing the license issue. raise_if_warnings_fatal! end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks transitive dependency licensing errors for the given software [CODESPLIT] def check_transitive_dependency_licensing_errors_for ( software ) reporter = LicenseScout :: Reporter . new ( license_output_dir ( software ) ) begin reporter . report . each { | i | transitive_dependency_licensing_warning ( i ) } rescue LicenseScout :: Exceptions :: InvalidOutputReport => e transitive_dependency_licensing_warning ( <<-EOH ) #{ license_output_dir ( software ) } #{ e } EOH end raise_if_warnings_fatal! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Collect the license files for the software . [CODESPLIT] def collect_licenses_for ( software ) return nil if software . license == :project_license software_name = software . name license_data = license_map [ software_name ] license_files = license_data [ :license_files ] license_files . each do | license_file | if license_file output_file = license_package_location ( software_name , license_file ) if local? ( license_file ) input_file = File . expand_path ( license_file , license_data [ :project_dir ] ) if File . exist? ( input_file ) FileUtils . cp ( input_file , output_file ) File . chmod 0644 , output_file unless windows? else licensing_warning ( \"License file '#{input_file}' does not exist for software '#{software_name}'.\" ) # If we got here, we need to fail now so we don't take a git # cache snapshot, or else the software build could be restored # from cache without fixing the license issue. raise_if_warnings_fatal! end else begin download_file! ( license_file , output_file , enable_progress_bar : false ) File . chmod 0644 , output_file unless windows? rescue SocketError , Errno :: ECONNREFUSED , Errno :: ECONNRESET , Errno :: ENETUNREACH , Timeout :: Error , OpenURI :: HTTPError , OpenSSL :: SSL :: SSLError licensing_warning ( \"Can not download license file '#{license_file}' for software '#{software_name}'.\" ) # If we got here, we need to fail now so we don't take a git # cache snapshot, or else the software build could be restored # from cache without fixing the license issue. raise_if_warnings_fatal! end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy all scripts in { Project#package_scripts_path } to the control directory of this repo . [CODESPLIT] def write_scripts SCRIPT_MAP . each do | source , destination | source_path = File . join ( project . package_scripts_path , source . to_s ) next unless File . file? ( source_path ) destination_path = staging_dir_path ( destination ) log . debug ( log_key ) { \"Adding script `#{source}' to `#{destination_path}'\" } copy_file ( source_path , destination_path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a Prototype file for solaris build [CODESPLIT] def write_prototype_file shellout! \"cd #{install_dirname} && find #{install_basename} -print > #{staging_dir_path('files')}\" File . open staging_dir_path ( \"files.clean\" ) , \"w+\" do | fout | File . open staging_dir_path ( \"files\" ) do | fin | fin . each_line do | line | if line . chomp =~ / \\s / log . warn ( log_key ) { \"Skipping packaging '#{line}' file due to whitespace in filename\" } else fout . write ( line ) end end end end # generate list of control files File . open staging_dir_path ( \"Prototype\" ) , \"w+\" do | f | f . write <<-EOF . gsub ( / / , \"\" ) EOF end # generate the prototype's file list shellout! \"cd #{install_dirname} && pkgproto < #{staging_dir_path('files.clean')} > #{staging_dir_path('Prototype.files')}\" # fix up the user and group in the file list to root shellout! \"awk '{ $5 = \\\"root\\\"; $6 = \\\"root\\\"; print }' < #{staging_dir_path('Prototype.files')} >> #{staging_dir_path('Prototype')}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a pkginfo file for solaris build [CODESPLIT] def write_pkginfo_file hostname = Socket . gethostname # http://docs.oracle.com/cd/E19683-01/816-0219/6m6njqbat/index.html pkginfo_content = <<-EOF . gsub ( / / , \"\" ) #{ install_dirname } #{ project . package_name } #{ project . package_name } #{ safe_architecture } #{ pkgmk_version } #{ project . description } #{ project . maintainer } #{ project . maintainer } #{ hostname } #{ Time . now . utc . iso8601 } EOF File . open staging_dir_path ( \"pkginfo\" ) , \"w+\" do | f | f . write pkginfo_content end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The actual contents of the package . [CODESPLIT] def content @content ||= IO . read ( path ) rescue Errno :: ENOENT raise NoPackageFile . new ( path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validate the presence of the required components for the package . [CODESPLIT] def validate! unless File . exist? ( path ) raise NoPackageFile . new ( path ) end unless File . exist? ( metadata . path ) raise NoPackageMetadataFile . new ( metadata . path ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The unique upload key for this package . The additional stuff is postfixed to the end of the path . [CODESPLIT] def key_for ( package , * stuff ) File . join ( Config . s3_publish_pattern % package . metadata , stuff ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new BuildVersion [CODESPLIT] def semver build_tag = version_tag # PRERELEASE VERSION if prerelease_version? # ensure all dashes are dots per precedence rules (#12) in Semver # 2.0.0-rc.1 prerelease = prerelease_tag . tr ( \"-\" , \".\" ) build_tag << \"-\" << prerelease end # BUILD VERSION # Follows SemVer conventions and the build version begins with a '+'. build_version_items = [ ] # By default we will append a timestamp to every build. This behavior can # be overriden by setting the OMNIBUS_APPEND_TIMESTAMP environment # variable to a 'falsey' value (ie false, f, no, n or 0). # # format: YYYYMMDDHHMMSS example: 20130131123345 if Config . append_timestamp build_version_items << build_start_time end # We'll append the git describe information unless we are sitting right # on an annotated tag. # # format: git.COMMITS_SINCE_TAG.GIT_SHA example: git.207.694b062 unless commits_since_tag == 0 build_version_items << [ \"git\" , commits_since_tag , git_sha_tag ] . join ( \".\" ) end unless build_version_items . empty? build_tag << \"+\" << build_version_items . join ( \".\" ) end build_tag end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "We ll attempt to retrieve the timestamp from the Jenkin s set BUILD_TIMESTAMP or fall back to BUILD_ID environment variable . This will ensure platform specfic packages for the same build will share the same timestamp . [CODESPLIT] def build_start_time @build_start_time ||= begin if ENV [ \"BUILD_TIMESTAMP\" ] begin Time . strptime ( ENV [ \"BUILD_TIMESTAMP\" ] , \"%Y-%m-%d_%H-%M-%S\" ) rescue ArgumentError error_message = \"BUILD_TIMESTAMP environment variable \" error_message << \"should be in YYYY-MM-DD_hh-mm-ss \" error_message << \"format.\" raise ArgumentError , error_message end elsif ENV [ \"BUILD_ID\" ] begin Time . strptime ( ENV [ \"BUILD_ID\" ] , \"%Y-%m-%d_%H-%M-%S\" ) rescue ArgumentError error_message = \"BUILD_ID environment variable \" error_message << \"should be in YYYY-MM-DD_hh-mm-ss \" error_message << \"format.\" raise ArgumentError , error_message end else Time . now . utc end end . strftime ( TIMESTAMP_FORMAT ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates a version string by running { https : // www . kernel . org / pub / software / scm / git / docs / git - describe . html git describe } in the root of the Omnibus project . [CODESPLIT] def git_describe @git_describe ||= begin cmd = shellout ( \"git describe --tags\" , cwd : @path ) if cmd . exitstatus == 0 cmd . stdout . chomp else log . warn ( log_key ) do \"Could not extract version information from 'git describe'! \" \"Setting version to 0.0.0.\" end \"0.0.0\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Save the file to disk . [CODESPLIT] def save File . open ( path , \"w+\" ) do | f | f . write ( FFI_Yajl :: Encoder . encode ( to_hash , pretty : true ) ) end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or return the vendor who made this package . [CODESPLIT] def vendor ( val = NULL ) if null? ( val ) @vendor || \"Omnibus <omnibus@getchef.com>\" else unless val . is_a? ( String ) raise InvalidValue . new ( :vendor , \"be a String\" ) end @vendor = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or return the license for this package . [CODESPLIT] def license ( val = NULL ) if null? ( val ) @license || project . license else unless val . is_a? ( String ) raise InvalidValue . new ( :license , \"be a String\" ) end @license = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Mark filesystem directories with ownership and permissions specified in the filesystem package https : // git . fedorahosted . org / cgit / filesystem . git / plain / filesystem . spec [CODESPLIT] def mark_filesystem_directories ( fsdir ) if fsdir . eql? ( \"/\" ) || fsdir . eql? ( \"/usr/lib\" ) || fsdir . eql? ( \"/usr/share/empty\" ) \"%dir %attr(0555,root,root) #{fsdir}\" elsif filesystem_directories . include? ( fsdir ) \"%dir %attr(0755,root,root) #{fsdir}\" else \"%dir #{fsdir}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render an rpm spec file in + SPECS / # { name } . spec + using the supplied ERB template . [CODESPLIT] def write_rpm_spec # Create a map of scripts that exist and their contents scripts = SCRIPT_MAP . inject ( { } ) do | hash , ( source , destination ) | path = File . join ( project . package_scripts_path , source . to_s ) if File . file? ( path ) hash [ destination ] = File . read ( path ) end hash end # Get a list of all files files = FileSyncer . glob ( \"#{build_dir}/**/*\" ) . map { | path | build_filepath ( path ) } render_template ( resource_path ( \"spec.erb\" ) , destination : spec_file , variables : { name : safe_base_package_name , version : safe_version , iteration : safe_build_iteration , vendor : vendor , license : license , dist_tag : dist_tag , maintainer : project . maintainer , homepage : project . homepage , description : project . description , priority : priority , category : category , conflicts : project . conflicts , replaces : project . replaces , dependencies : project . runtime_dependencies , user : project . package_user , group : project . package_group , scripts : scripts , config_files : config_files , files : files , build_dir : build_dir , platform_family : Ohai [ \"platform_family\" ] , compression : compression , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate the RPM file using + rpmbuild + . Unlike debian the + fakeroot + command is not required for the package to be owned by + root : root + . The rpmuser specified in the spec file dictates this . [CODESPLIT] def create_rpm_file command = %{rpmbuild} command << %{ --target #{safe_architecture}} command << %{ -bb} command << %{ --buildroot #{staging_dir}/BUILD} command << %{ --define '_topdir #{staging_dir}'} if signing_passphrase log . info ( log_key ) { \"Signing enabled for .rpm file\" } if File . exist? ( \"#{ENV['HOME']}/.rpmmacros\" ) log . info ( log_key ) { \"Detected .rpmmacros file at `#{ENV['HOME']}'\" } home = ENV [ \"HOME\" ] else log . info ( log_key ) { \"Using default .rpmmacros file from Omnibus\" } # Generate a temporary home directory home = Dir . mktmpdir render_template ( resource_path ( \"rpmmacros.erb\" ) , destination : \"#{home}/.rpmmacros\" , variables : { gpg_name : project . maintainer , gpg_path : \"#{ENV['HOME']}/.gnupg\" , # TODO: Make this configurable } ) end command << \" --sign\" command << \" #{spec_file}\" with_rpm_signing do | signing_script | log . info ( log_key ) { \"Creating .rpm file\" } shellout! ( \"#{signing_script} \\\"#{command}\\\"\" , environment : { \"HOME\" => home } ) end else log . info ( log_key ) { \"Creating .rpm file\" } command << \" #{spec_file}\" shellout! ( \"#{command}\" ) end FileSyncer . glob ( \"#{staging_dir}/RPMS/**/*.rpm\" ) . each do | rpm | copy_file ( rpm , Config . package_dir ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert the path of a file in the staging directory to an entry for use in the spec file . [CODESPLIT] def build_filepath ( path ) filepath = rpm_safe ( \"/\" + path . gsub ( \"#{build_dir}/\" , \"\" ) ) return if config_files . include? ( filepath ) full_path = build_dir + filepath . gsub ( \"[%]\" , \"%\" ) # FileSyncer.glob quotes pathnames that contain spaces, which is a problem on el7 full_path . delete! ( '\"' ) # Mark directories with the %dir directive to prevent rpmbuild from counting their contents twice. return mark_filesystem_directories ( filepath ) if ! File . symlink? ( full_path ) && File . directory? ( full_path ) filepath end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the rpm signing script with secure permissions call the given block with the path to the script and ensure deletion of the script from disk since it contains sensitive information . [CODESPLIT] def with_rpm_signing ( & block ) directory = Dir . mktmpdir destination = \"#{directory}/sign-rpm\" render_template ( resource_path ( \"signing.erb\" ) , destination : destination , mode : 0700 , variables : { passphrase : signing_passphrase , } ) # Yield the destination to the block yield ( destination ) ensure remove_file ( destination ) remove_directory ( directory ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate an RPM - safe name from the given string doing the following : [CODESPLIT] def rpm_safe ( string ) string = \"\\\"#{string}\\\"\" if string [ / \\s / ] string . dup . gsub ( \"[\" , \"[\\\\[]\" ) . gsub ( \"*\" , \"[*]\" ) . gsub ( \"?\" , \"[?]\" ) . gsub ( \"%\" , \"[%]\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Shortcut method for executing a publisher . [CODESPLIT] def publish ( klass , pattern , options ) if options [ :platform_mappings ] options [ :platform_mappings ] = FFI_Yajl :: Parser . parse ( File . read ( File . expand_path ( options [ :platform_mappings ] ) ) ) end klass . publish ( pattern , options ) do | package | say ( \"Published '#{package.name}' for #{package.metadata[:platform]}-#{package.metadata[:platform_version]}\" , :green ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "** [ Required ] ** Set or retrieve the path at which the project should be installed by the generated package . [CODESPLIT] def install_dir ( val = NULL ) if null? ( val ) @install_dir || raise ( MissingRequiredAttribute . new ( self , :install_dir , \"/opt/chef\" ) ) else @install_dir = val . tr ( '\\\\' , \"/\" ) . squeeze ( \"/\" ) . chomp ( \"/\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or retrieve the version of the project . [CODESPLIT] def build_version ( val = NULL , & block ) if block && ! null? ( val ) raise Error , \"You cannot specify additional parameters to \" \"#build_version when a block is given!\" end if block @build_version_dsl = BuildVersionDSL . new ( block ) else if null? ( val ) @build_version_dsl . build_version else @build_version_dsl = BuildVersionDSL . new ( val ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add or override a customization for the packager with the given + id + . When given multiple blocks with the same + id + they are evaluated _in order_ so the last block evaluated will take precedence over the previous ones . [CODESPLIT] def package ( id , & block ) unless block raise InvalidValue . new ( :package , \"have a block\" ) end packagers [ id ] << block end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add or override a customization for the compressor with the given + id + . When given multiple blocks with the same + id + they are evaluated _in order_ so the last block evaluated will take precedence over the previous ones . [CODESPLIT] def compress ( id , & block ) if block compressors [ id ] << block else compressors [ id ] << Proc . new { } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set or retrieve the overrides hash for one piece of software being overridden . Calling it as a setter does not merge hash entries and it will set all the overrides for a given software definition . [CODESPLIT] def override ( name , val = NULL ) if null? ( val ) overrides [ name . to_sym ] else overrides [ name . to_sym ] = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Location of license file that omnibus will create and that will contain the information about the license of the project plus the details about the licenses of the software components included in the project . [CODESPLIT] def license_file_path ( path = NULL ) if null? ( path ) @license_file_path || File . join ( install_dir , \"LICENSE\" ) else @license_file_path = File . join ( install_dir , path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Indicates whether the given + software + is defined as a software component of this project . [CODESPLIT] def dependency? ( software ) name = software . is_a? ( Software ) ? software . name : software dependencies . include? ( name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a version manifest of the loaded software sources . [CODESPLIT] def built_manifest log . info ( log_key ) { \"Building version manifest\" } m = Omnibus :: Manifest . new ( build_version , build_git_revision , license ) softwares . each do | software | m . add ( software . name , software . manifest_entry ) end m end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes a text manifest to the text_manifest_path . This uses the same method as the version - manifest software definition in omnibus - software . [CODESPLIT] def write_text_manifest File . open ( text_manifest_path , \"w\" ) do | f | f . puts \"#{name} #{build_version}\" f . puts \"\" f . puts Omnibus :: Reports . pretty_version_map ( self ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compression level ( 1 - 9 ) to use ( - Z ) . [CODESPLIT] def compression_level ( val = NULL ) if null? ( val ) @compression_level || 9 else unless val . is_a? ( Integer ) && 1 <= val && 9 >= val raise InvalidValue . new ( :compression_level , \"be an Integer between 1 and 9\" ) end @compression_level = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compression strategy to use ( - Z ) . For gzip : : filtered : huffman : rle or : fixed ; for xz : : extreme ( nil means parameter will not be passsed to dpkg - deb ) [CODESPLIT] def compression_strategy ( val = NULL ) if null? ( val ) @compression_strategy else unless val . is_a? ( Symbol ) && [ :filtered , :huffman , :rle , :fixed , :extreme ] . member? ( val ) raise InvalidValue . new ( :compression_strategy , \"be a Symbol (:filtered, \" \":huffman, :rle, :fixed, or :extreme)\" ) end @compression_strategy = val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a control file in + # { debian_dir } / control + using the supplied ERB template . [CODESPLIT] def write_control_file render_template ( resource_path ( \"control.erb\" ) , destination : File . join ( debian_dir , \"control\" ) , variables : { name : safe_base_package_name , version : safe_version , iteration : safe_build_iteration , vendor : vendor , license : license , architecture : safe_architecture , maintainer : project . maintainer , installed_size : package_size , homepage : project . homepage , description : project . description , priority : priority , section : section , conflicts : project . conflicts , replaces : project . replaces , dependencies : project . runtime_dependencies , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the list of config files into the conffile . [CODESPLIT] def write_conffiles_file return if project . config_files . empty? render_template ( resource_path ( \"conffiles.erb\" ) , destination : File . join ( debian_dir , \"conffiles\" ) , variables : { config_files : project . config_files , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy all scripts in { Project#package_scripts_path } to the control directory of this repo . [CODESPLIT] def write_scripts %w{ preinst postinst prerm postrm } . each do | script | path = File . join ( project . package_scripts_path , script ) if File . file? ( path ) log . debug ( log_key ) { \"Adding script `#{script}' to `#{debian_dir}' from #{path}\" } copy_file ( path , debian_dir ) log . debug ( log_key ) { \"SCRIPT FILE:  #{debian_dir}/#{script}\" } FileUtils . chmod ( 0755 , File . join ( debian_dir , script ) ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a list of the md5 sums of every file in the package and write it to + # { debian_dir } / control / md5sums + . [CODESPLIT] def write_md5_sums path = \"#{staging_dir}/**/*\" hash = FileSyncer . glob ( path ) . inject ( { } ) do | hash , path | if File . file? ( path ) && ! File . symlink? ( path ) && ! ( File . dirname ( path ) == debian_dir ) relative_path = path . gsub ( \"#{staging_dir}/\" , \"\" ) hash [ relative_path ] = digest ( path , :md5 ) end hash end render_template ( resource_path ( \"md5sums.erb\" ) , destination : File . join ( debian_dir , \"md5sums\" ) , variables : { md5sums : hash , } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sign the + . deb + file with gpg . This has to be done as separate steps from creating the + . deb + file . See + debsigs + source for behavior replicated here . + https : // gitlab . com / debsigs / debsigs / blob / master / debsigs . txt#L103 - 124 + [CODESPLIT] def sign_deb_file if ! signing_passphrase log . info ( log_key ) { \"Signing not enabled for .deb file\" } return end log . info ( log_key ) { \"Signing enabled for .deb file\" } # Check our dependencies and determine command for GnuPG. +Omnibus.which+ returns the path, or nil. gpg = nil if Omnibus . which ( \"gpg2\" ) gpg = \"gpg2\" elsif Omnibus . which ( \"gpg\" ) gpg = \"gpg\" end if gpg && Omnibus . which ( \"ar\" ) # Create a directory that will be cleaned when we leave the block Dir . mktmpdir do | tmp_dir | Dir . chdir ( tmp_dir ) do # Extract the deb file contents shellout! ( \"ar x #{Config.package_dir}/#{package_name}\" ) # Concatenate contents, in order per +debsigs+ documentation. shellout! ( \"cat debian-binary control.tar.* data.tar.* > complete\" ) # Create signature (as +root+) gpg_command = \"#{gpg} --armor --sign --detach-sign\" gpg_command << \" --local-user '#{project.maintainer}'\" gpg_command << \" --homedir #{ENV['HOME']}/.gnupg\" # TODO: Make this configurable ## pass the +signing_passphrase+ via +STDIN+ gpg_command << \" --batch --no-tty\" ## Check `gpg` for the compatibility/need of pinentry-mode # - We're calling gpg with the +--pinentry-mode+ argument, and +STDIN+ of +/dev/null+ # - This _will_ fail with exit code 2 no matter what. We want to check the +STDERR+ #   for the error message about the parameter. If it is _not present_ in the #   output, then we _do_ want to add it. (If +grep -q+ is +1+, add parameter) if shellout ( \"#{gpg} --pinentry-mode loopback </dev/null 2>&1 | grep -q pinentry-mode\" ) . exitstatus == 1 gpg_command << \" --pinentry-mode loopback\" end gpg_command << \" --passphrase-fd 0\" gpg_command << \" -o _gpgorigin complete\" shellout! ( \"fakeroot #{gpg_command}\" , input : signing_passphrase ) # Append +_gpgorigin+ to the +.deb+ file (as +root+) shellout! ( \"fakeroot ar rc #{Config.package_dir}/#{package_name} _gpgorigin\" ) end end else log . info ( log_key ) { \"Signing not possible. Ensure that GnuPG and GNU AR are available\" } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The size of this Debian package . This is dynamically calculated . [CODESPLIT] def package_size @package_size ||= begin path = \"#{project.install_dir}/**/*\" total = FileSyncer . glob ( path ) . inject ( 0 ) do | size , path | unless File . directory? ( path ) || File . symlink? ( path ) size += File . size ( path ) end size end # Per http://www.debian.org/doc/debian-policy/ch-controlfields.html, the # disk space is given as the integer value of the estimated installed # size in bytes, divided by 1024 and rounded up. total / 1024 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the Debian - ready base package name converting any invalid characters to dashes ( + - + ) . [CODESPLIT] def safe_base_package_name if project . package_name =~ / \\A \\. \\+ \\- \\z / project . package_name . dup else converted = project . package_name . downcase . gsub ( / \\. \\+ \\- / , \"-\" ) log . warn ( log_key ) do \"The `name' component of Debian package names can only include \" \"lower case alphabetical characters (a-z), numbers (0-9), dots (.), \" \"plus signs (+), and dashes (-). Converting `#{project.package_name}' to \" \"`#{converted}'.\" end converted end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the Debian - ready version replacing all dashes ( + - + ) with tildes ( + ~ + ) and converting any invalid characters to underscores ( + _ + ) . [CODESPLIT] def safe_version version = project . build_version . dup if version =~ / \\- / converted = version . tr ( \"-\" , \"~\" ) log . warn ( log_key ) do \"Dashes hold special significance in the Debian package versions. \" \"Versions that contain a dash and should be considered an earlier \" \"version (e.g. pre-releases) may actually be ordered as later \" \"(e.g. 12.0.0-rc.6 > 12.0.0). We'll work around this by replacing \" \"dashes (-) with tildes (~). Converting `#{project.build_version}' \" \"to `#{converted}'.\" end version = converted end if version =~ / \\A \\. \\+ \\: \\~ \\z / version else converted = version . gsub ( / \\. \\+ \\: \\~ / , \"_\" ) log . warn ( log_key ) do \"The `version' component of Debian package names can only include \" \"alphabetical characters (a-z, A-Z), numbers (0-9), dots (.), \" \"plus signs (+), dashes (-), tildes (~) and colons (:). Converting \" \"`#{project.build_version}' to `#{converted}'.\" end converted end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fetch ( clone ) or update ( fetch ) the remote git repository . [CODESPLIT] def fetch log . info ( log_key ) { \"Fetching from `#{source_url}'\" } create_required_directories if cloned? git_fetch else force_recreate_project_dir! unless dir_empty? ( project_dir ) git_clone end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine if a directory is empty [CODESPLIT] def dir_empty? ( dir ) Dir . entries ( dir ) . reject { | d | [ \".\" , \"..\" ] . include? ( d ) } . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Forcibly remove and recreate the project directory [CODESPLIT] def force_recreate_project_dir! log . warn ( log_key ) { \"Removing existing directory #{project_dir} before cloning\" } FileUtils . rm_rf ( project_dir ) Dir . mkdir ( project_dir ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The current revision for the cloned checkout . [CODESPLIT] def current_revision cmd = git ( \"rev-parse HEAD\" ) cmd . stdout . strip rescue CommandFailed log . debug ( log_key ) { \"unable to determine current revision\" } nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if the current clone has the requested commit id . [CODESPLIT] def contains_revision? ( rev ) cmd = git ( \"cat-file -t #{rev}\" ) cmd . stdout . strip == \"commit\" rescue CommandFailed log . debug ( log_key ) { \"unable to determine presence of commit #{rev}\" } false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts a BN object to a string . The format used is that which is required by the SSH2 protocol . [CODESPLIT] def to_ssh if zero? return [ 0 ] . pack ( \"N\" ) else buf = to_s ( 2 ) if buf . getbyte ( 0 ) [ 7 ] == 1 return [ buf . length + 1 , 0 , buf ] . pack ( \"NCA*\" ) else return [ buf . length , buf ] . pack ( \"NA*\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compute the number of bits needed for the given number of bytes . [CODESPLIT] def compute_need_bits # for Compatibility: OpenSSH requires (need_bits * 2 + 1) length of parameter need_bits = data [ :need_bytes ] * 8 * 2 + 1 data [ :minimum_dh_bits ] ||= MINIMUM_BITS if need_bits < data [ :minimum_dh_bits ] need_bits = data [ :minimum_dh_bits ] elsif need_bits > MAXIMUM_BITS need_bits = MAXIMUM_BITS end data [ :need_bits ] = need_bits data [ :need_bytes ] = need_bits / 8 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the DH key parameters for the given session . [CODESPLIT] def get_parameters compute_need_bits # request the DH key parameters for the given number of bits. buffer = Net :: SSH :: Buffer . from ( :byte , KEXDH_GEX_REQUEST , :long , data [ :minimum_dh_bits ] , :long , data [ :need_bits ] , :long , MAXIMUM_BITS ) connection . send_message ( buffer ) buffer = connection . next_message raise Net :: SSH :: Exception , \"expected KEXDH_GEX_GROUP, got #{buffer.type}\" unless buffer . type == KEXDH_GEX_GROUP p = buffer . read_bignum g = buffer . read_bignum [ p , g ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build the signature buffer to use when verifying a signature from the server . [CODESPLIT] def build_signature_buffer ( result ) response = Net :: SSH :: Buffer . new response . write_string data [ :client_version_string ] , data [ :server_version_string ] , data [ :client_algorithm_packet ] , data [ :server_algorithm_packet ] , result [ :key_blob ] response . write_long MINIMUM_BITS , data [ :need_bits ] , MAXIMUM_BITS response . write_bignum dh . p , dh . g , dh . pub_key , result [ :server_dh_pubkey ] , result [ :shared_secret ] response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes the given block after the page is loaded . [CODESPLIT] def when_loaded # Get original loaded value, in case we are nested # inside another when_loaded block. previously_loaded = loaded # Within the block, check (and cache) loaded?, to see whether the # page has indeed loaded according to the rules defined by the user. self . loaded = loaded? # If the page hasn't loaded. Then crash and return the error message. # If one isn't defined, just return the Error code. raise SitePrism :: FailedLoadValidationError , load_error unless loaded # Return the yield value of the block if one was supplied. yield self if block_given? ensure self . loaded = previously_loaded end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If any load validations from page subclasses returns false immediately return false . [CODESPLIT] def load_validations_pass? self . class . load_validations . all? do | validation | passed , message = instance_eval ( validation ) self . load_error = message if message && ! passed passed end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prevent users from calling methods with blocks when they shouldn t be . [CODESPLIT] def raise_if_block ( obj , name , has_block , type ) return unless has_block SitePrism . logger . debug ( \"Type passed in: #{type}\" ) SitePrism . logger . warn ( 'section / iFrame can only accept blocks.' ) SitePrism . logger . error ( \"#{obj.class}##{name} does not accept blocks\" ) raise SitePrism :: UnsupportedBlockError end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sanitize method called before calling any SitePrism DSL method or meta - programmed method . This ensures that the Capybara query is correct . [CODESPLIT] def merge_args ( find_args , runtime_args , visibility_args = { } ) find_args = find_args . dup runtime_args = runtime_args . dup options = visibility_args . dup SitePrism . logger . debug ( \"Initial args: #{find_args}, #{runtime_args}.\" ) recombine_args ( find_args , runtime_args , options ) return [ find_args , runtime_args ] if options . empty? [ find_args , runtime_args , options ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options re - combiner . This takes the original inputs and combines them such that there is only one hash passed as a final argument to Capybara . [CODESPLIT] def recombine_args ( find_args , runtime_args , options ) options . merge! ( find_args . pop ) if find_args . last . is_a? Hash options . merge! ( runtime_args . pop ) if runtime_args . last . is_a? Hash options [ :wait ] = wait_time unless wait_key_present? ( options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runnable in the scope of any SitePrism :: Page or Section . Returns + true + when every item that is being checked is present within the current scope . See #elements_to_check for how the definition of every item is derived . [CODESPLIT] def all_there? ( recursion : 'none' ) SitePrism . logger . info ( 'Setting for recursion is being ignored for now.' ) if %w[ none one ] . include? ( recursion ) elements_to_check . all? { | item_name | there? ( item_name ) } else SitePrism . logger . error ( 'Invalid recursion setting, Will not run.' ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If the page or section has expected_items set return expected_items that are mapped ; otherwise just return the list of all mapped_items [CODESPLIT] def elements_to_check if _expected_items SitePrism . logger . debug ( 'Expected Items has been set.' ) _mapped_items . select { | item_name | _expected_items . include? ( item_name ) } else _mapped_items end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Loads the page . @param expansion_or_html @param block [ &block ] An optional block to run once the page is loaded . The page will yield the block if defined . [CODESPLIT] def load ( expansion_or_html = { } , & block ) self . loaded = false SitePrism . logger . debug ( \"Reset loaded state on #{self.class}.\" ) return_yield = if expansion_or_html . is_a? ( String ) load_html_string ( expansion_or_html , block ) else load_html_website ( expansion_or_html , block ) end # Ensure that we represent that the page we loaded is now indeed loaded! # This ensures that future calls to #loaded? do not perform the # instance evaluations against all load validations procs another time. self . loaded = true SitePrism . logger . info ( \"#{self.class} loaded.\" ) # Return the yield from the block if there was one, otherwise return true return_yield || true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine whether URL matches our pattern and optionally whether the extracted mappings match a hash of expected values . You can specify values as strings numbers or regular expressions . [CODESPLIT] def matches? ( url , expected_mappings = { } ) actual_mappings = mappings ( url ) return false unless actual_mappings expected_mappings . empty? || all_expected_mappings_match? ( expected_mappings , actual_mappings ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns empty hash if the template omits the component or a set of substitutions if the provided URI component matches the template component or nil if the match fails . [CODESPLIT] def component_matches ( component , uri ) component_template = component_templates [ component ] return { } unless component_template component_url = uri . public_send ( component ) . to_s mappings = component_template . extract ( component_url ) return mappings if mappings # to support Addressable's expansion of queries # ensure it's parsing the fragment as appropriate (e.g. {?params*}) prefix = component_prefixes [ component ] return nil unless prefix component_template . extract ( prefix + component_url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert the pattern into an Addressable URI by substituting the template slugs with nonsense strings . [CODESPLIT] def to_substituted_uri url = pattern substitutions . each_pair { | slug , value | url = url . sub ( slug , value ) } begin Addressable :: URI . parse ( url ) rescue Addressable :: URI :: InvalidURIError SitePrism . logger . warn ( \"Ensure you don't use templated port numbers.\" ) raise SitePrism :: InvalidUrlMatcherError end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a repeatable 5 character uniform alphabetical nonsense string to allow parsing as a URI [CODESPLIT] def substitution_value ( index ) sha = Digest :: SHA1 . digest ( index . to_s ) Base64 . urlsafe_encode64 ( sha ) . gsub ( / / , '' ) [ 0 .. 5 ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds Enumerator objects that iterates N times and yields number starting from zero . [CODESPLIT] def build_times_enumerator ( number , cursor : ) raise ArgumentError , \"First argument must be an Integer\" unless number . is_a? ( Integer ) wrap ( self , build_array_enumerator ( number . times . to_a , cursor : cursor ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds Enumerator object from a given array using + cursor + as an offset . [CODESPLIT] def build_array_enumerator ( enumerable , cursor : ) unless enumerable . is_a? ( Array ) raise ArgumentError , \"enumerable must be an Array\" end if enumerable . any? { | i | defined? ( ActiveRecord ) && i . is_a? ( ActiveRecord :: Base ) } raise ArgumentError , \"array cannot contain ActiveRecord objects\" end drop = if cursor . nil? 0 else cursor + 1 end wrap ( self , enumerable . each_with_index . drop ( drop ) . to_enum { enumerable . size } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds Enumerator from a lock queue instance that belongs to a job . The helper is only to be used from jobs that use LockQueue module . [CODESPLIT] def build_lock_queue_enumerator ( lock_queue , at_most_once : ) unless lock_queue . is_a? ( BackgroundQueue :: LockQueue :: RedisQueue ) || lock_queue . is_a? ( BackgroundQueue :: LockQueue :: RolloutRedisQueue ) raise ArgumentError , \"an argument to #build_lock_queue_enumerator must be a LockQueue\" end wrap ( self , BackgroundQueue :: LockQueueEnumerator . new ( lock_queue , at_most_once : at_most_once ) . to_enum ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds Enumerator from Active Record Relation . Each Enumerator tick moves the cursor one row forward . [CODESPLIT] def build_active_record_enumerator_on_records ( scope , cursor : , ** args ) enum = build_active_record_enumerator ( scope , cursor : cursor , ** args ) . records wrap ( self , enum ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds Enumerator from Active Record Relation and enumerates on batches . Each Enumerator tick moves the cursor + batch_size + rows forward . [CODESPLIT] def build_active_record_enumerator_on_batches ( scope , cursor : , ** args ) enum = build_active_record_enumerator ( scope , cursor : cursor , ** args ) . batches wrap ( self , enum ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Constructs a enumerator on batches of CSV rows [CODESPLIT] def batches ( batch_size : , cursor : ) @csv . lazy . each_slice ( batch_size ) . each_with_index . drop ( cursor . to_i ) . to_enum { ( count_rows_in_file . to_f / batch_size ) . ceil } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Restore the item from this version . [CODESPLIT] def reify ( options = { } ) unless self . class . column_names . include? \"object\" raise \"reify can't be called without an object column\" end return nil if object . nil? :: PaperTrail :: Reifier . reify ( self , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Enforces the version_limit if set . Default : no limit . [CODESPLIT] def enforce_version_limit! limit = version_limit return unless limit . is_a? Numeric previous_versions = sibling_versions . not_creates . order ( self . class . timestamp_sort_order ( \"asc\" ) ) return unless previous_versions . size > limit excess_versions = previous_versions - previous_versions . last ( limit ) excess_versions . map ( :destroy ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See docs section 2 . e . Limiting the Number of Versions Created . The version limit can be global or per - model . [CODESPLIT] def version_limit if self . class . item_subtype_column_present? klass = ( item_subtype || item_type ) . constantize if klass &. paper_trail_options &. key? ( :limit ) return klass . paper_trail_options [ :limit ] end end PaperTrail . config . version_limit end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns [CODESPLIT] def sequence if @version_class . primary_key_is_int? @versions . select ( primary_key ) . order ( primary_key . asc ) else @versions . select ( [ table [ :created_at ] , primary_key ] ) . order ( @version_class . timestamp_sort_order ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Destroys all but the most recent version ( s ) for items on a given date ( or on all dates ) . Useful for deleting drafts . [CODESPLIT] def clean_versions! ( options = { } ) options = { keeping : 1 , date : :all } . merge ( options ) gather_versions ( options [ :item_id ] , options [ :date ] ) . each do | _item_id , item_versions | group_versions_by_date ( item_versions ) . each do | _date , date_versions | # Remove the number of versions we wish to keep from the collection # of versions prior to destruction. date_versions . pop ( options [ :keeping ] ) date_versions . map ( :destroy ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a hash of versions grouped by the item_id attribute formatted like this : { : item_id = > PaperTrail :: Version } . If item_id or date is set versions will be narrowed to those pointing at items with those ids that were created on specified date . Versions are returned in chronological order . [CODESPLIT] def gather_versions ( item_id = nil , date = :all ) unless date == :all || date . respond_to? ( :to_date ) raise ArgumentError , \"Expected date to be a Timestamp or :all\" end versions = item_id ? PaperTrail :: Version . where ( item_id : item_id ) : PaperTrail :: Version versions = versions . order ( PaperTrail :: Version . timestamp_sort_order ) versions = versions . between ( date . to_date , date . to_date + 1 . day ) unless date == :all # If `versions` has not been converted to an ActiveRecord::Relation yet, # do so now. versions = PaperTrail :: Version . all if versions == PaperTrail :: Version versions . group_by ( :item_id ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a callback that records a version after a create event . [CODESPLIT] def on_create @model_class . after_create { | r | r . paper_trail . record_create if r . paper_trail . save_version? } return if @model_class . paper_trail_options [ :on ] . include? ( :create ) @model_class . paper_trail_options [ :on ] << :create end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a callback that records a version before or after a destroy event . [CODESPLIT] def on_destroy ( recording_order = \"before\" ) unless %w[ after before ] . include? ( recording_order . to_s ) raise ArgumentError , 'recording order can only be \"after\" or \"before\"' end if recording_order . to_s == \"after\" && cannot_record_after_destroy? raise E_CANNOT_RECORD_AFTER_DESTROY end @model_class . send ( \"#{recording_order}_destroy\" , lambda do | r | return unless r . paper_trail . save_version? r . paper_trail . record_destroy ( recording_order ) end ) return if @model_class . paper_trail_options [ :on ] . include? ( :destroy ) @model_class . paper_trail_options [ :on ] << :destroy end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a callback that records a version after an update event . [CODESPLIT] def on_update @model_class . before_save { | r | r . paper_trail . reset_timestamp_attrs_for_update_if_needed } @model_class . after_update { | r | if r . paper_trail . save_version? r . paper_trail . record_update ( force : false , in_after_callback : true , is_touch : false ) end } @model_class . after_update { | r | r . paper_trail . clear_version_instance } return if @model_class . paper_trail_options [ :on ] . include? ( :update ) @model_class . paper_trail_options [ :on ] << :update end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a callback that records a version after a touch event . [CODESPLIT] def on_touch @model_class . after_touch { | r | r . paper_trail . record_update ( force : true , in_after_callback : true , is_touch : true ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set up [CODESPLIT] def setup ( options = { } ) options [ :on ] ||= %i[ create update destroy touch ] options [ :on ] = Array ( options [ :on ] ) # Support single symbol @model_class . send :include , :: PaperTrail :: Model :: InstanceMethods setup_options ( options ) setup_associations ( options ) check_presence_of_item_subtype_column ( options ) @model_class . after_rollback { paper_trail . clear_rolled_back_versions } setup_callbacks_from_options options [ :on ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Some options require the presence of the item_subtype column . Currently only limit but in the future there may be others . [CODESPLIT] def check_presence_of_item_subtype_column ( options ) return unless options . key? ( :limit ) return if version_class . item_subtype_column_present? raise format ( E_MODEL_LIMIT_REQUIRES_ITEM_SUBTYPE , @model_class . name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "recording_order is after or before . See ModelConfig#on_destroy . [CODESPLIT] def record_destroy ( recording_order ) return unless enabled? && ! @record . new_record? in_after_callback = recording_order == \"after\" event = Events :: Destroy . new ( @record , in_after_callback ) # Merge data from `Event` with data from PT-AT. We no longer use # `data_for_destroy` but PT-AT still does. data = event . data . merge ( data_for_destroy ) version = @record . class . paper_trail . version_class . create ( data ) if version . errors . any? log_version_errors ( version , :destroy ) else assign_and_reset_version_association ( version ) version end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "AR callback . [CODESPLIT] def save_version? if_condition = @record . paper_trail_options [ :if ] unless_condition = @record . paper_trail_options [ :unless ] ( if_condition . blank? || if_condition . call ( @record ) ) && ! unless_condition . try ( :call , @record ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Save and create a version record regardless of options such as : on : if or : unless . [CODESPLIT] def save_with_version ( * args ) :: PaperTrail . request ( enabled : false ) do @record . save ( args ) end record_update ( force : true , in_after_callback : false , is_touch : false ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like the update_columns method from ActiveRecord :: Persistence but also creates a version to record those changes . [CODESPLIT] def update_columns ( attributes ) # `@record.update_columns` skips dirty-tracking, so we can't just use # `@record.changes` or @record.saved_changes` from `ActiveModel::Dirty`. # We need to build our own hash with the changes that will be made # directly to the database. changes = { } attributes . each do | k , v | changes [ k ] = [ @record [ k ] , v ] end @record . update_columns ( attributes ) record_update_columns ( changes ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the object ( not a Version ) as it was at the given timestamp . [CODESPLIT] def version_at ( timestamp , reify_options = { } ) # Because a version stores how its object looked *before* the change, # we need to look for the first version created *after* the timestamp. v = versions . subsequent ( timestamp , true ) . first return v . reify ( reify_options ) if v @record unless @record . destroyed? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the objects ( not Versions ) as they were between the given times . [CODESPLIT] def versions_between ( start_time , end_time ) versions = send ( @record . class . versions_association_name ) . between ( start_time , end_time ) versions . collect { | version | version_at ( version . created_at ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Invalidate some part of the snapshot / record ( dir file subtree etc . ) [CODESPLIT] def invalidate ( type , rel_path , options ) watched_dir = Pathname . new ( record . root ) change = options [ :change ] cookie = options [ :cookie ] if ! cookie && config . silenced? ( rel_path , type ) Listen :: Logger . debug { \"(silenced): #{rel_path.inspect}\" } return end path = watched_dir + rel_path Listen :: Logger . debug do log_details = options [ :silence ] && 'recording' || change || 'unknown' \"#{log_details}: #{type}:#{path} (#{options.inspect})\" end if change options = cookie ? { cookie : cookie } : { } config . queue ( type , change , watched_dir , rel_path , options ) elsif type == :dir # NOTE: POSSIBLE RECURSION # TODO: fix - use a queue instead Directory . scan ( self , rel_path , options ) else change = File . change ( record , rel_path ) return if ! change || options [ :silence ] config . queue ( :file , change , watched_dir , rel_path ) end rescue RuntimeError => ex msg = format ( '%s#%s crashed %s:%s' , self . class , __method__ , exinspect , ex . backtrace * \"\\n\" ) Listen :: Logger . error ( msg ) raise end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Note : relative_path is temporarily expected to be a relative Pathname to make refactoring easier ( ideally it would take a string ) TODO : switch type and path places - and verify [CODESPLIT] def silenced? ( relative_path , type ) path = relative_path . to_s if only_patterns && type == :file return true unless only_patterns . any? { | pattern | path =~ pattern } end ignore_patterns . any? { | pattern | path =~ pattern } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "groups changes into the expected structure expected by clients [CODESPLIT] def _squash_changes ( changes ) # We combine here for backward compatibility # Newer clients should receive dir and path separately changes = changes . map { | change , dir , path | [ change , dir + path ] } actions = changes . group_by ( :last ) . map do | path , action_list | [ _logical_action_for ( path , action_list . map ( :first ) ) , path . to_s ] end config . debug ( \"listen: raw changes: #{actions.inspect}\" ) { modified : [ ] , added : [ ] , removed : [ ] } . tap do | squashed | actions . each do | type , path | squashed [ type ] << path unless type . nil? end config . debug ( \"listen: final changes: #{squashed.inspect}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "remove extraneous rb - inotify events keeping them only if it s a possible editor rename () call ( e . g . Kate and Sublime ) [CODESPLIT] def _reinterpret_related_changes ( cookies ) table = { moved_to : :added , moved_from : :removed } cookies . flat_map do | _ , changes | data = _detect_possible_editor_save ( changes ) if data to_dir , to_file = data [ [ :modified , to_dir , to_file ] ] else not_silenced = changes . reject do | type , _ , _ , path , _ | config . silenced? ( Pathname ( path ) , type ) end not_silenced . map do | _ , change , dir , path , _ | [ table . fetch ( change , change ) , dir , path ] end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fetch tree node if necessary [CODESPLIT] def to_node object if object . is_a? ( self . ancestry_base_class ) then object else unscoped_where { | scope | scope . find object } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Scope on relative depth options [CODESPLIT] def scope_depth depth_options , depth depth_options . inject ( self . ancestry_base_class ) do | scope , option | scope_name , relative_depth = option if [ :before_depth , :to_depth , :at_depth , :from_depth , :after_depth ] . include? scope_name scope . send scope_name , depth + relative_depth else raise Ancestry :: AncestryException . new ( \"Unknown depth option: #{scope_name}.\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Orphan strategy writer [CODESPLIT] def orphan_strategy = orphan_strategy # Check value of orphan strategy, only rootify, adopt, restrict or destroy is allowed if [ :rootify , :adopt , :restrict , :destroy ] . include? orphan_strategy class_variable_set :@@orphan_strategy , orphan_strategy else raise Ancestry :: AncestryException . new ( \"Invalid orphan strategy, valid ones are :rootify,:adopt, :restrict and :destroy.\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all nodes and sorting them into an empty hash [CODESPLIT] def arrange options = { } if ( order = options . delete ( :order ) ) arrange_nodes self . ancestry_base_class . order ( order ) . where ( options ) else arrange_nodes self . ancestry_base_class . where ( options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Arrange array of nodes into a nested hash of the form { node = > children } where children = {} if the node has no children If a node s parent is not included the node will be included as if it is a top level node [CODESPLIT] def arrange_nodes ( nodes ) node_ids = Set . new ( nodes . map ( :id ) ) index = Hash . new { | h , k | h [ k ] = { } } nodes . each_with_object ( { } ) do | node , arranged | children = index [ node . id ] index [ node . parent_id ] [ node ] = children arranged [ node ] = children unless node_ids . include? ( node . parent_id ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Arrangement to nested array [CODESPLIT] def arrange_serializable options = { } , nodes = nil , & block nodes = arrange ( options ) if nodes . nil? nodes . map do | parent , children | if block_given? yield parent , arrange_serializable ( options , children , block ) else parent . serializable_hash . merge 'children' => arrange_serializable ( options , children ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pseudo - preordered array of nodes . Children will always follow parents for ordering nodes within a rank provide block eg . Node . sort_by_ancestry ( Node . all ) { |a b| a . rank < = > b . rank } . [CODESPLIT] def sort_by_ancestry ( nodes , & block ) arranged = nodes if nodes . is_a? ( Hash ) unless arranged presorted_nodes = nodes . sort do | a , b | a_cestry , b_cestry = a . ancestry || '0' , b . ancestry || '0' if block_given? && a_cestry == b_cestry yield a , b else a_cestry <=> b_cestry end end arranged = arrange_nodes ( presorted_nodes ) end arranged . inject ( [ ] ) do | sorted_nodes , pair | node , children = pair sorted_nodes << node sorted_nodes += sort_by_ancestry ( children , block ) unless children . blank? sorted_nodes end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Integrity checking [CODESPLIT] def check_ancestry_integrity! options = { } parents = { } exceptions = [ ] if options [ :report ] == :list unscoped_where do | scope | # For each node ... scope . find_each do | node | begin # ... check validity of ancestry column if ! node . valid? and ! node . errors [ node . class . ancestry_column ] . blank? raise Ancestry :: AncestryIntegrityException . new ( \"Invalid format for ancestry column of node #{node.id}: #{node.read_attribute node.ancestry_column}.\" ) end # ... check that all ancestors exist node . ancestor_ids . each do | ancestor_id | unless exists? ancestor_id raise Ancestry :: AncestryIntegrityException . new ( \"Reference to non-existent node in node #{node.id}: #{ancestor_id}.\" ) end end # ... check that all node parents are consistent with values observed earlier node . path_ids . zip ( [ nil ] + node . path_ids ) . each do | node_id , parent_id | parents [ node_id ] = parent_id unless parents . has_key? node_id unless parents [ node_id ] == parent_id raise Ancestry :: AncestryIntegrityException . new ( \"Conflicting parent id found in node #{node.id}: #{parent_id || 'nil'} for node #{node_id} while expecting #{parents[node_id] || 'nil'}\" ) end end rescue Ancestry :: AncestryIntegrityException => integrity_exception case options [ :report ] when :list then exceptions << integrity_exception when :echo then puts integrity_exception else raise integrity_exception end end end end exceptions if options [ :report ] == :list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Integrity restoration [CODESPLIT] def restore_ancestry_integrity! parents = { } # Wrap the whole thing in a transaction ... self . ancestry_base_class . transaction do unscoped_where do | scope | # For each node ... scope . find_each do | node | # ... set its ancestry to nil if invalid if ! node . valid? and ! node . errors [ node . class . ancestry_column ] . blank? node . without_ancestry_callbacks do node . update_attribute node . ancestry_column , nil end end # ... save parent of this node in parents array if it exists parents [ node . id ] = node . parent_id if exists? node . parent_id # Reset parent id in array to nil if it introduces a cycle parent = parents [ node . id ] until parent . nil? || parent == node . id parent = parents [ parent ] end parents [ node . id ] = nil if parent == node . id end # For each node ... scope . find_each do | node | # ... rebuild ancestry from parents array ancestry , parent = nil , parents [ node . id ] until parent . nil? ancestry , parent = if ancestry . nil? then parent else \"#{parent}/#{ancestry}\" end , parents [ parent ] end node . without_ancestry_callbacks do node . update_attribute node . ancestry_column , ancestry end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build ancestry from parent id s for migration purposes [CODESPLIT] def build_ancestry_from_parent_ids! parent_id = nil , ancestry = nil unscoped_where do | scope | scope . where ( :parent_id => parent_id ) . find_each do | node | node . without_ancestry_callbacks do node . update_attribute ancestry_column , ancestry end build_ancestry_from_parent_ids! node . id , if ancestry . nil? then \"#{node.id}\" else \"#{ancestry}/#{node.id}\" end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rebuild depth cache if it got corrupted or if depth caching was just turned on [CODESPLIT] def rebuild_depth_cache! raise Ancestry :: AncestryException . new ( \"Cannot rebuild depth cache for model without depth caching.\" ) unless respond_to? :depth_cache_column self . ancestry_base_class . transaction do unscoped_where do | scope | scope . find_each do | node | node . update_attribute depth_cache_column , node . depth end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update descendants with new ancestry ( before save ) [CODESPLIT] def update_descendants_with_new_ancestry # If enabled and node is existing and ancestry was updated and the new ancestry is sane ... if ! ancestry_callbacks_disabled? && ! new_record? && ancestry_changed? && sane_ancestry? # ... for each descendant ... unscoped_descendants . each do | descendant | # ... replace old ancestry with new ancestry descendant . without_ancestry_callbacks do descendant . update_attribute ( self . ancestry_base_class . ancestry_column , descendant . read_attribute ( descendant . class . ancestry_column ) . gsub ( # child_ancestry_was / #{ self . child_ancestry } / , # future child_ancestry if ancestors? then \"#{read_attribute self.class.ancestry_column }/#{id}\" else id . to_s end ) ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Apply orphan strategy ( before destroy - no changes ) [CODESPLIT] def apply_orphan_strategy if ! ancestry_callbacks_disabled? && ! new_record? case self . ancestry_base_class . orphan_strategy when :rootify # make all children root if orphan strategy is rootify unscoped_descendants . each do | descendant | descendant . without_ancestry_callbacks do new_ancestry = if descendant . ancestry == child_ancestry nil else # child_ancestry did not change so child_ancestry_was will work here descendant . ancestry . gsub ( / #{ child_ancestry } \\/ / , '' ) end descendant . update_attribute descendant . class . ancestry_column , new_ancestry end end when :destroy # destroy all descendants if orphan strategy is destroy unscoped_descendants . each do | descendant | descendant . without_ancestry_callbacks do descendant . destroy end end when :adopt # make child elements of this node, child of its parent descendants . each do | descendant | descendant . without_ancestry_callbacks do new_ancestry = descendant . ancestor_ids . delete_if { | x | x == self . id } . join ( \"/\" ) # check for empty string if it's then set to nil new_ancestry = nil if new_ancestry . empty? descendant . update_attribute descendant . class . ancestry_column , new_ancestry || nil end end when :restrict # throw an exception if it has children raise Ancestry :: AncestryException . new ( 'Cannot delete record because it has descendants.' ) unless is_childless? end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Touch each of this record s ancestors ( after save ) [CODESPLIT] def touch_ancestors_callback if ! ancestry_callbacks_disabled? && self . ancestry_base_class . touch_ancestors # Touch each of the old *and* new ancestors unscoped_current_and_previous_ancestors . each do | ancestor | ancestor . without_ancestry_callbacks do ancestor . touch end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The ancestry value for this record s children ( before save ) This is technically child_ancestry_was [CODESPLIT] def child_ancestry # New records cannot have children raise Ancestry :: AncestryException . new ( 'No child ancestry for new record. Save record before performing tree operations.' ) if new_record? if self . send ( \"#{self.ancestry_base_class.ancestry_column}#{IN_DATABASE_SUFFIX}\" ) . blank? id . to_s else \"#{self.send \"#{self.ancestry_base_class.ancestry_column}#{IN_DATABASE_SUFFIX}\"}/#{id}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "indirect = anyone who is a descendant but not a child [CODESPLIT] def indirect_conditions ( object ) t = arel_table node = to_node ( object ) # rails has case sensitive matching. if ActiveRecord :: VERSION :: MAJOR >= 5 t [ ancestry_column ] . matches ( \"#{node.child_ancestry}/%\" , nil , true ) else t [ ancestry_column ] . matches ( \"#{node.child_ancestry}/%\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "increment_failure_of [CODESPLIT] def increment_failure_of ( setting_name ) self [ setting_name ] [ :failures ] += 1 Sail . reset ( setting_name ) if self [ setting_name ] [ :failures ] > Sail . configuration . failures_until_reset end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable AbcSize [CODESPLIT] def index @settings = Setting . by_query ( s_params [ :query ] ) . ordered_by ( s_params [ :order_field ] ) @number_of_pages = ( @settings . count . to_f / settings_per_page ) . ceil @settings = @settings . paginated ( s_params [ :page ] , settings_per_page ) fresh_when ( @settings ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable AbcSize [CODESPLIT] def update respond_to do | format | @setting , @successful_update = Setting . set ( s_params [ :name ] , s_params [ :value ] ) format . js { } format . json { @successful_update ? head ( :ok ) : head ( :conflict ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks the response code for common errors . Returns parsed response for successful requests . [CODESPLIT] def validate ( response ) error_klass = Error :: STATUS_MAPPINGS [ response . code ] raise error_klass , response if error_klass parsed = response . parsed_response parsed . client = self if parsed . respond_to? ( :client= ) parsed . parse_headers! ( response . headers ) if parsed . respond_to? ( :parse_headers! ) parsed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets a base_uri and default_params for requests . [CODESPLIT] def request_defaults ( sudo = nil ) self . class . default_params sudo : sudo raise Error :: MissingCredentials , 'Please set an endpoint to API' unless @endpoint self . class . default_params . delete ( :sudo ) if sudo . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a hash of options and their values . [CODESPLIT] def options VALID_OPTIONS_KEYS . inject ( { } ) do | option , key | option . merge! ( key => send ( key ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Resets all configuration options to the defaults . [CODESPLIT] def reset self . endpoint = ENV [ 'GITLAB_API_ENDPOINT' ] self . private_token = ENV [ 'GITLAB_API_PRIVATE_TOKEN' ] || ENV [ 'GITLAB_API_AUTH_TOKEN' ] self . httparty = get_httparty_config ( ENV [ 'GITLAB_API_HTTPARTY_OPTIONS' ] ) self . sudo = nil self . user_agent = DEFAULT_USER_AGENT end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allows HTTParty config to be specified in ENV using YAML hash . [CODESPLIT] def get_httparty_config ( options ) return if options . nil? httparty = Gitlab :: CLI :: Helpers . yaml_load ( options ) raise ArgumentError , 'HTTParty config should be a Hash.' unless httparty . is_a? Hash Gitlab :: CLI :: Helpers . symbolize_keys httparty end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Start a timer in the included object [CODESPLIT] def start_timer ( timer = DEFAULT_TIMER . new ) raise Socketry :: InternalError , \"timer already started\" if defined? ( @timer ) raise Socketry :: InternalError , \"deadline already set\" if defined? ( @deadline ) @deadline = nil @timer = timer @timer . start true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set a timeout . Only one timeout may be active at a given time for a given object . [CODESPLIT] def set_timeout ( timeout ) raise Socketry :: InternalError , \"deadline already set\" if @deadline return unless timeout raise Socketry :: TimeoutError , \"time expired\" if timeout < 0 @deadline = lifetime + timeout end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate number of seconds remaining until we hit the timeout [CODESPLIT] def time_remaining ( timeout ) return unless timeout raise Socketry :: InternalError , \"no deadline set\" unless @deadline remaining = @deadline - lifetime raise Socketry :: TimeoutError , \"time expired\" if remaining <= 0 remaining end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run a simple true / false validation of data against a schema [CODESPLIT] def validate @base_schema . validate ( @data , [ ] , self , @validation_options ) if @options [ :record_errors ] if @options [ :errors_as_objects ] @errors . map { | e | e . to_hash } else @errors . map { | e | e . to_string } end else true end ensure if @validation_options [ :clear_cache ] == true self . class . clear_cache end if @validation_options [ :insert_defaults ] self . class . merge_missing_values ( @data , @original_data ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build all schemas with IDs mapping out the namespace [CODESPLIT] def build_schemas ( parent_schema ) schema = parent_schema . schema # Build ref schemas if they exist if schema [ \"$ref\" ] load_ref_schema ( parent_schema , schema [ \"$ref\" ] ) end case schema [ \"extends\" ] when String load_ref_schema ( parent_schema , schema [ \"extends\" ] ) when Array schema [ 'extends' ] . each do | type | handle_schema ( parent_schema , type ) end end # Check for schemas in union types [ \"type\" , \"disallow\" ] . each do | key | if schema [ key ] . is_a? ( Array ) schema [ key ] . each do | type | if type . is_a? ( Hash ) handle_schema ( parent_schema , type ) end end end end # Schema properties whose values are objects, the values of which # are themselves schemas. %w[ definitions properties patternProperties ] . each do | key | next unless value = schema [ key ] value . each do | k , inner_schema | handle_schema ( parent_schema , inner_schema ) end end # Schema properties whose values are themselves schemas. %w[ additionalProperties additionalItems dependencies extends ] . each do | key | next unless schema [ key ] . is_a? ( Hash ) handle_schema ( parent_schema , schema [ key ] ) end # Schema properties whose values may be an array of schemas. %w[ allOf anyOf oneOf not ] . each do | key | next unless value = schema [ key ] Array ( value ) . each do | inner_schema | handle_schema ( parent_schema , inner_schema ) end end # Items are always schemas if schema [ \"items\" ] items = schema [ \"items\" ] . clone items = [ items ] unless items . is_a? ( Array ) items . each do | item | handle_schema ( parent_schema , item ) end end # Convert enum to a ArraySet if schema [ \"enum\" ] . is_a? ( Array ) schema [ \"enum\" ] = ArraySet . new ( schema [ \"enum\" ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Either load a reference schema or create a new schema [CODESPLIT] def handle_schema ( parent_schema , obj ) if obj . is_a? ( Hash ) schema_uri = parent_schema . uri . dup schema = JSON :: Schema . new ( obj , schema_uri , parent_schema . validator ) if obj [ 'id' ] self . class . add_schema ( schema ) end build_schemas ( schema ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a Hash containing as keys all local branches that have upstream branches and as values a brief description of each branch s status relative to its upstream branch ( up to date or ahead / behind ) [CODESPLIT] def get_upstream_branches command_to_a ( \"git branch -vv\" ) . map do | line | line . gsub! ( LEADING_STAR_REGEX , \"\" ) branch_name = line . split ( BRANCH_NAME_REGEX ) [ 0 ] remote_info = line [ REMOTE_INFO_REGEX , 1 ] if remote_info . nil? nil else comparison_raw = remote_info . split ( \":\" ) comparison = if comparison_raw . length < 2 \"Up to date\" else comparison_raw [ 1 ] . strip . capitalize end [ branch_name , comparison ] end end . compact . to_h end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Matches the block or conditions hash [CODESPLIT] def matches_conditions? ( action , subject , extra_args ) if @match_all call_block_with_all ( action , subject , extra_args ) elsif @block && ! subject_class? ( subject ) @block . call ( subject , extra_args ) elsif @conditions . kind_of? ( Hash ) && subject . class == Hash nested_subject_matches_conditions? ( subject ) elsif @conditions . kind_of? ( Hash ) && ! subject_class? ( subject ) matches_conditions_hash? ( subject ) else # Don't stop at \"cannot\" definitions when there are conditions. @conditions . empty? ? true : @base_behavior end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if the given subject matches the given conditions hash . This behavior can be overriden by a model adapter by defining two class methods : override_matching_for_conditions? ( subject conditions ) and matches_conditions_hash? ( subject conditions ) [CODESPLIT] def matches_conditions_hash? ( subject , conditions = @conditions ) if conditions . empty? true else if model_adapter ( subject ) . override_conditions_hash_matching? subject , conditions model_adapter ( subject ) . matches_conditions_hash? subject , conditions else conditions . all? do | name , value | if model_adapter ( subject ) . override_condition_matching? subject , name , value model_adapter ( subject ) . matches_condition? subject , name , value else attribute = subject . send ( name ) if value . kind_of? ( Hash ) if attribute . kind_of? Array attribute . any? { | element | matches_conditions_hash? element , value } else ! attribute . nil? && matches_conditions_hash? ( attribute , value ) end elsif ! value . is_a? ( String ) && value . kind_of? ( Enumerable ) value . include? attribute else attribute == value end end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Alias one or more actions into another one . [CODESPLIT] def alias_action ( * args ) target = args . pop [ :to ] validate_target ( target ) aliased_actions [ target ] ||= [ ] aliased_actions [ target ] += args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See ControllerAdditions#authorize! for documentation . [CODESPLIT] def authorize! ( action , subject , * args ) message = nil if args . last . kind_of? ( Hash ) && args . last . has_key? ( :message ) message = args . pop [ :message ] end if cannot? ( action , subject , args ) message ||= unauthorized_message ( action , subject ) raise AccessDenied . new ( message , action , subject ) end subject end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Accepts an array of actions and returns an array of actions which match . This should be called before matches? and other checking methods since they rely on the actions to be expanded . [CODESPLIT] def expand_actions ( actions ) actions . map do | action | aliased_actions [ action ] ? [ action , expand_actions ( aliased_actions [ action ] ) ] : action end . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given an action it will try to find all of the actions which are aliased to it . This does the opposite kind of lookup as expand_actions . [CODESPLIT] def aliases_for_action ( action ) results = [ action ] aliased_actions . each do | aliased_action , actions | results += aliases_for_action ( aliased_action ) if actions . include? action end results end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array of Rule instances which match the action and subject This does not take into consideration any hash conditions or block statements [CODESPLIT] def relevant_rules ( action , subject ) rules . reverse . select do | rule | rule . expanded_actions = expand_actions ( rule . actions ) rule . relevant? action , subject end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def load_resource_instance if parent? @controller . send :association_chain @controller . instance_variable_get ( \"@#{instance_name}\" ) elsif new_actions . include? @params [ :action ] . to_sym resource = @controller . send :build_resource assign_attributes ( resource ) else @controller . send :resource end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the class used for this resource . This can be overriden by the : class option . If + false + is passed in it will use the resource name as a symbol in which case it should only be used for authorization not loading since there s no class to load through . [CODESPLIT] def resource_class case @options [ :class ] when false then name . to_sym when nil then namespaced_name . to_s . camelize . constantize when String then @options [ :class ] . constantize else @options [ :class ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The object that methods ( such as find new or build ) are called on . If the : through option is passed it will go through an association on that instance . If the : shallow option is passed it will use the resource_class if there s no parent If the : singleton option is passed it won t use the association because it needs to be handled later . [CODESPLIT] def resource_base if @options [ :through ] if parent_resource @options [ :singleton ] ? resource_class : parent_resource . send ( @options [ :through_association ] || name . to_s . pluralize ) elsif @options [ :shallow ] resource_class else raise AccessDenied . new ( nil , authorization_action , resource_class ) # maybe this should be a record not found error instead? end else resource_class end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a missing file if the path is valid . [CODESPLIT] def create_missing_file raise Errno :: EISDIR , path . to_s if File . directory? ( @path ) return if File . exist? ( @path ) # Unnecessary check, probably. dirname = RealFile . dirname @path unless dirname == '.' dir = FileSystem . find dirname raise Errno :: ENOENT , path . to_s unless dir . is_a? FakeDir end @file = FileSystem . add ( path , FakeFile . new ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a pathname which is substituted by String#sub . [CODESPLIT] def sub ( pattern , * rest , & block ) path = if block @path . sub ( pattern , rest ) do | * args | begin old = Thread . current [ :pathname_sub_matchdata ] Thread . current [ :pathname_sub_matchdata ] = $~ # TODO: rewrite without using eval eval ( '$~ = Thread.current[:pathname_sub_matchdata]' , block . binding , __FILE__ , __LINE__ - 3 ) ensure Thread . current [ :pathname_sub_matchdata ] = old end yield ( args ) end else @path . sub ( pattern , rest ) end self . class . new ( path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "#mountpoint? returns + true + if <tt > self< / tt > points to a mountpoint . [CODESPLIT] def mountpoint? stat1 = lstat begin stat2 = parent . lstat stat1 . dev == stat2 . dev && stat1 . ino == stat2 . ino || stat1 . dev != stat2 . dev rescue Errno :: ENOENT false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates over each component of the path . [CODESPLIT] def each_filename # :yield: filename return to_enum ( __method__ ) unless block_given? _prefix , names = split_names ( @path ) names . each { | filename | yield filename } nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates over and yields a new Pathname object for each element in the given path in descending order . [CODESPLIT] def descend vs = [ ] ascend { | v | vs << v } vs . reverse_each { | v | yield v } nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates over and yields a new Pathname object for each element in the given path in ascending order . [CODESPLIT] def ascend path = @path yield self while ( r = chop_basename ( path ) ) path , _name = r break if path . empty? yield self . class . new ( del_trailing_separator ( path ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pathname# + appends a pathname fragment to this one to produce a new Pathname object . [CODESPLIT] def + ( other ) other = Pathname . new ( other ) unless other . is_a? ( Pathname ) Pathname . new ( plus ( @path , other . to_s ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pathname#join joins pathnames . [CODESPLIT] def join ( * args ) args . unshift self result = args . pop result = Pathname . new ( result ) unless result . is_a? ( Pathname ) return result if result . absolute? args . reverse_each do | arg | arg = Pathname . new ( arg ) unless arg . is_a? ( Pathname ) result = arg + result return result if result . absolute? end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the children of the directory ( files and subdirectories not recursive ) as an array of Pathname objects . By default the returned pathnames will have enough information to access the files . If you set + with_directory + to + false + then the returned pathnames will contain the filename only . [CODESPLIT] def children ( with_directory = true ) with_directory = false if @path == '.' result = [ ] Dir . foreach ( @path ) do | e | next if [ '.' , '..' ] . include? ( e ) result << if with_directory self . class . new ( File . join ( @path , e ) ) else self . class . new ( e ) end end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "#relative_path_from returns a relative path from the argument to the receiver . If + self + is absolute the argument must be absolute too . If + self + is relative the argument must be relative too . [CODESPLIT] def relative_path_from ( base_directory ) dest_directory = cleanpath . to_s base_directory = base_directory . cleanpath . to_s dest_prefix = dest_directory dest_names = [ ] while ( r = chop_basename ( dest_prefix ) ) dest_prefix , basename = r dest_names . unshift basename if basename != '.' end base_prefix = base_directory base_names = [ ] while ( r = chop_basename ( base_prefix ) ) base_prefix , basename = r base_names . unshift basename if basename != '.' end unless SAME_PATHS [ dest_prefix , base_prefix ] raise ArgumentError , \"different prefix: #{dest_prefix.inspect} \" \"and #{base_directory.inspect}\" end while ! dest_names . empty? && ! base_names . empty? && SAME_PATHS [ dest_names . first , base_names . first ] dest_names . shift base_names . shift end if base_names . include? '..' raise ArgumentError , \"base_directory has ..: #{base_directory.inspect}\" end base_names . fill ( '..' ) relpath_names = base_names + dest_names if relpath_names . empty? Pathname . new ( '.' ) else Pathname . new ( File . join ( relpath_names ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "chop_basename ( path ) - > [ pre - basename basename ] or nil [CODESPLIT] def chop_basename ( path ) base = File . basename ( path ) if / \\A #{ SEPARATOR_PAT } \\z /o =~ base return nil else return path [ 0 , path . rindex ( base ) ] , base end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "split_names ( path ) - > prefix [ name ... ] [CODESPLIT] def split_names ( path ) names = [ ] while ( r = chop_basename ( path ) ) path , basename = r names . unshift basename end [ path , names ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Clean the path simply by resolving and removing excess . and .. entries . Nothing more nothing less . [CODESPLIT] def cleanpath_aggressive path = @path names = [ ] pre = path while ( r = chop_basename ( pre ) ) pre , base = r case base when '.' # rubocop:disable Lint/EmptyWhen when '..' names . unshift base else if names [ 0 ] == '..' names . shift else names . unshift base end end end if / #{ SEPARATOR_PAT } /o =~ File . basename ( pre ) names . shift while names [ 0 ] == '..' end self . class . new ( prepend_prefix ( pre , File . join ( names ) ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "trailing_separator? ( path ) - > bool [CODESPLIT] def trailing_separator? ( path ) if ( r = chop_basename ( path ) ) pre , basename = r pre . length + basename . length < path . length else false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "* IO * [CODESPLIT] def each_line ( * args , & block ) # :yield: line if block_given? File . open ( @path , 'r' ) do | io | io . each_line ( args , block ) end else enum_for ( :each_line , args ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See <tt > File . write< / tt > . Returns the number of bytes written . [CODESPLIT] def write ( string , * args ) offset = args [ 0 ] open_args = args [ 1 ] File . open ( @path , open_args || 'w' ) do | file | file . seek ( offset ) if offset return file . write ( string ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "* Find * [CODESPLIT] def find ( * ) # :yield: pathname require 'find' if @path == '.' Find . find ( @path ) { | f | yield self . class . new ( f . sub ( %r{ \\A \\. } , '' ) ) } else Find . find ( @path ) { | f | yield self . class . new ( f ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the C checksum based on checksum_values [CODESPLIT] def c_checksum sum = 0 checksum_values . each_with_index do | value , index | sum += ( ( index % 20 ) + 1 ) * value end sum % 47 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the K checksum based on checksum_values_with_c_checksum [CODESPLIT] def k_checksum sum = 0 checksum_values_with_c_checksum . each_with_index do | value , index | sum += ( ( index % 15 ) + 1 ) * value end sum % 47 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an instance of Magick :: Image [CODESPLIT] def to_image ( opts = { } ) with_options opts do canvas = Magick :: Image . new ( full_width , full_height ) bars = Magick :: Draw . new x1 = margin y1 = margin if barcode . two_dimensional? encoding . each do | line | line . split ( / / ) . map { | c | c == '1' } . each do | bar | if bar x2 = x1 + ( xdim - 1 ) y2 = y1 + ( ydim - 1 ) # For single pixels use point if x1 == x2 && y1 == y2 bars . point ( x1 , y1 ) else bars . rectangle ( x1 , y1 , x2 , y2 ) end end x1 += xdim end x1 = margin y1 += ydim end else booleans . each do | bar | if bar x2 = x1 + ( xdim - 1 ) y2 = y1 + ( height - 1 ) bars . rectangle ( x1 , y1 , x2 , y2 ) end x1 += xdim end end bars . draw ( canvas ) canvas end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Annotate a PDFWriter document with the barcode [CODESPLIT] def annotate_pdf ( pdf , options = { } ) with_options options do xpos , ypos = x , y orig_xpos = xpos if barcode . two_dimensional? boolean_groups . reverse_each do | groups | groups . each do | bar , amount | if bar pdf . move_to ( xpos , ypos ) . line_to ( xpos , ypos + xdim ) . line_to ( xpos + ( xdim amount ) , ypos + xdim ) . line_to ( xpos + ( xdim amount ) , ypos ) . line_to ( xpos , ypos ) . fill end xpos += ( xdim amount ) end xpos = orig_xpos ypos += xdim end else boolean_groups . each do | bar , amount | if bar pdf . move_to ( xpos , ypos ) . line_to ( xpos , ypos + height ) . line_to ( xpos + ( xdim amount ) , ypos + height ) . line_to ( xpos + ( xdim amount ) , ypos ) . line_to ( xpos , ypos ) . fill end xpos += ( xdim amount ) end end end pdf end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts the barcode s encoding ( a string containing 1s and 0s ) to true and false values ( 1 == true == black bar ) [CODESPLIT] def booleans ( reload = false ) #:doc: if two_dimensional? encoding ( reload ) . map { | l | l . split ( / / ) . map { | c | c == '1' } } else encoding ( reload ) . split ( / / ) . map { | c | c == '1' } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Collects continuous groups of bars and spaces ( 1 and 0 ) into arrays where the first item is true or false ( 1 or 0 ) and the second is the size of the group [CODESPLIT] def boolean_groups ( reload = false ) if two_dimensional? encoding ( reload ) . map do | line | line . scan ( / / ) . map do | group | [ group [ 0 , 1 ] == '1' , group . size ] end end else encoding ( reload ) . scan ( / / ) . map do | group | [ group [ 0 , 1 ] == '1' , group . size ] end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Takes a hash and temporarily sets properties on self ( the outputter object ) corresponding with the keys to their values . When the block exits the properties are reset to their original values . Returns whatever the block returns . [CODESPLIT] def with_options ( options = { } ) original_options = options . inject ( { } ) do | origs , pair | if respond_to? ( pair . first ) && respond_to? ( \"#{pair.first}=\" ) origs [ pair . first ] = send ( pair . first ) send ( \"#{pair.first}=\" , pair . last ) end origs end rv = yield original_options . each do | attribute , value | send ( \"#{attribute}=\" , value ) end rv end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the encodable characters . If extended mode is enabled each character will first be replaced by two characters from the encodable charset [CODESPLIT] def characters chars = raw_characters extended ? chars . map { | c | EXTENDED_ENCODINGS [ c ] . split ( / / ) } . flatten : chars end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Takes an array of WIDE / NARROW values and returns the string representation for those bars and spaces using wide_width and narrow_width [CODESPLIT] def encoding_for_bars ( * bars_and_spaces ) bar = false bars_and_spaces . flatten . map do | width | bar = ! bar ( bar ? '1' : '0' ) * ( width == WIDE ? wide_width : narrow_width ) end . join end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a PNG :: Canvas object and renders the barcode on it [CODESPLIT] def to_image ( opts = { } ) with_options opts do canvas = ChunkyPNG :: Image . new ( full_width , full_height , ChunkyPNG :: Color :: WHITE ) if barcode . two_dimensional? x , y = margin , margin booleans . each do | line | line . each do | bar | if bar x . upto ( x + ( xdim - 1 ) ) do | xx | y . upto y + ( ydim - 1 ) do | yy | canvas [ xx , yy ] = ChunkyPNG :: Color :: BLACK end end end x += xdim end y += ydim x = margin end else x , y = margin , margin booleans . each do | bar | if bar x . upto ( x + ( xdim - 1 ) ) do | xx | y . upto y + ( height - 1 ) do | yy | canvas [ xx , yy ] = ChunkyPNG :: Color :: BLACK end end end x += xdim end end canvas end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a ChunkyPNG :: Datastream containing the barcode image [CODESPLIT] def to_datastream ( * a ) constraints = a . first && a . first [ :constraints ] ? [ a . first [ :constraints ] ] : [ ] to_image ( a ) . to_datastream ( constraints ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the data for this barcode . If the barcode changes character set an extra will be created . [CODESPLIT] def data = ( data ) data , * extra = data . split ( / #{ CODEA + CODEB + CODEC } /n ) @data = data || '' self . extra = extra . join unless extra . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the extra for this barcode . The argument is a string starting with the change character set symbol . The string may contain several character sets in which case the extra will itself have an extra . [CODESPLIT] def extra = ( extra ) raise ArgumentError , \"Extra must begin with \\\\305, \\\\306 or \\\\307\" unless extra =~ / #{ CODEA + CODEB + CODEC } /n type , data = extra [ 0 , 1 ] , extra [ 1 .. - 1 ] @extra = class_for ( type ) . new ( data ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get an array of the individual characters for this barcode . Special characters like FNC1 will be present . Characters from extras are not present . [CODESPLIT] def characters chars = data . split ( / /n ) if type == 'C' result = [ ] count = 0 while count < chars . size if chars [ count ] =~ / \\d / #If encountering a digit, next char/byte *must* be second digit in pair. I.e. if chars[count] is 5, #chars[count+1] must be /[0-9]/, otherwise it's not valid result << \"#{chars[count]}#{chars[count+1]}\" count += 2 else result << chars [ count ] count += 1 end end result else chars end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the checksum for the data in this barcode . The data includes data from extras . [CODESPLIT] def checksum pos = 0 ( numbers + extra_numbers ) . inject ( start_num ) do | sum , number | pos += 1 sum + ( number * pos ) end % 103 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate encoding for an array of W N [CODESPLIT] def encoding_for_bars ( * bars ) wide , narrow , space = wide_encoding , narrow_encoding , space_encoding bars . flatten . inject '' do | enc , bar | enc + ( bar == WIDE ? wide : narrow ) + space end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Mod10 [CODESPLIT] def checksum evens , odds = even_and_odd_digits sum = odds . inject ( 0 ) { | s , d | s + d } + evens . inject ( 0 ) { | s , d | s + ( d 3 ) } sum %= 10 sum . zero? ? 0 : 10 - sum end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the barcode onto a Cairo context [CODESPLIT] def render_to_cairo_context ( context , options = { } ) if context . respond_to? ( :have_current_point? ) and context . have_current_point? current_x , current_y = context . current_point else current_x = x ( options ) || margin ( options ) current_y = y ( options ) || margin ( options ) end _xdim = xdim ( options ) _height = height ( options ) original_current_x = current_x context . save do context . set_source_color ( :black ) context . fill do if barcode . two_dimensional? boolean_groups . each do | groups | groups . each do | bar , amount | current_width = _xdim * amount if bar context . rectangle ( current_x , current_y , current_width , _xdim ) end current_x += current_width end current_x = original_current_x current_y += _xdim end else boolean_groups . each do | bar , amount | current_width = _xdim * amount if bar context . rectangle ( current_x , current_y , current_width , _height ) end current_x += current_width end end end end context end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the barcode to a PNG image [CODESPLIT] def to_png ( options = { } ) output_to_string_io do | io | Cairo :: ImageSurface . new ( options [ :format ] , full_width ( options ) , full_height ( options ) ) do | surface | render ( surface , options ) surface . write_to_png ( io ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the barcode to a PS document [CODESPLIT] def to_ps ( options = { } ) output_to_string_io do | io | Cairo :: PSSurface . new ( io , full_width ( options ) , full_height ( options ) ) do | surface | surface . eps = options [ :eps ] if surface . respond_to? ( :eps= ) render ( surface , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the barcode to a PDF document [CODESPLIT] def to_pdf ( options = { } ) output_to_string_io do | io | Cairo :: PDFSurface . new ( io , full_width ( options ) , full_height ( options ) ) do | surface | render ( surface , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render the barcode to an SVG document [CODESPLIT] def to_svg ( options = { } ) output_to_string_io do | io | Cairo :: SVGSurface . new ( io , full_width ( options ) , full_height ( options ) ) do | surface | render ( surface , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Encodes an array of interleaved W or N bars and spaces ex : [ W N W W N N ] = > 111011100010 [CODESPLIT] def encoding_for_interleaved ( * bars_and_spaces ) bar = false #starts with bar bars_and_spaces . flatten . inject '' do | enc , bar_or_space | bar = ! bar enc << ( bar ? '1' : '0' ) * ( bar_or_space == WIDE ? wide_width : narrow_width ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Hash ] params [CODESPLIT] def request_params ( params = { } ) default_request_params . merge ( params ) do | key , oldval , newval | key == :headers ? oldval . merge ( newval ) : newval end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] xpath @param [ Regexp ] pattern @param [ Typhoeus :: Response String ] page [CODESPLIT] def xpath_pattern_from_page ( xpath , pattern , page = nil ) page = NS :: Browser . get ( url ( page ) ) unless page . is_a? ( Typhoeus :: Response ) matches = [ ] page . html . xpath ( xpath ) . each do | node | next unless node . text . strip =~ pattern yield Regexp . last_match , node if block_given? matches << [ Regexp . last_match , node ] end matches end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Regexp ] pattern @param [ Typhoeus :: Response String ] page [CODESPLIT] def comments_from_page ( pattern , page = nil ) xpath_pattern_from_page ( '//comment()' , pattern , page ) do | match , node | yield match , node if block_given? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Regexp ] pattern @param [ Typhoeus :: Response String ] page [CODESPLIT] def javascripts_from_page ( pattern , page = nil ) xpath_pattern_from_page ( '//script' , pattern , page ) do | match , node | yield match , node if block_given? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Typhoeus :: Response String ] page @param [ String ] xpath [CODESPLIT] def uris_from_page ( page = nil , xpath = '//@href|//@src|//@data-src' ) page = NS :: Browser . get ( url ( page ) ) unless page . is_a? ( Typhoeus :: Response ) found = [ ] page . html . xpath ( xpath ) . each do | node | attr_value = node . text . to_s next unless attr_value && ! attr_value . empty? node_uri = begin uri . join ( attr_value . strip ) rescue StandardError # Skip potential malformed URLs etc. next end next unless node_uri . host yield node_uri , node . parent if block_given? && ! found . include? ( node_uri ) found << node_uri end found . uniq end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String Addressable :: URI ] url An absolute URL or URI [CODESPLIT] def in_scope? ( url_or_uri ) url_or_uri = Addressable :: URI . parse ( url_or_uri . strip ) unless url_or_uri . is_a? ( Addressable :: URI ) scope . include? ( url_or_uri . host ) rescue StandardError false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Typhoeus :: Response ] res @param [ String ] xpath [CODESPLIT] def in_scope_uris ( res , xpath = '//@href|//@src|//@data-src' ) found = [ ] uris_from_page ( res , xpath ) do | uri , tag | next unless in_scope? ( uri ) yield uri , tag if block_given? found << uri end found end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Similar to Target#url_pattern but considering the in scope domains as well [CODESPLIT] def scope_url_pattern return @scope_url_pattern if @scope_url_pattern domains = [ uri . host + uri . path ] domains += if scope . domains . empty? [ scope . invalid_domains [ 1 .. - 1 ] ] else [ scope . domains [ 1 .. - 1 ] ] . map ( :to_s ) + scope . invalid_domains end domains . map! { | d | Regexp . escape ( d . gsub ( %r{ } , '' ) ) . gsub ( '\\*' , '.*' ) . gsub ( '/' , '\\\\\\\\\\?/' ) } domains [ 0 ] . gsub! ( Regexp . escape ( uri . host ) , Regexp . escape ( uri . host ) + '(?::\\\\d+)?' ) if uri . port @scope_url_pattern = %r{ \\\\ \\\\ #{ domains . join ( '|' ) } \\\\ }i end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "For Sanity [CODESPLIT] def match ( pattern ) pattern = PublicSuffix . parse ( pattern ) unless pattern . is_a? ( PublicSuffix :: Domain ) return name == pattern . name unless pattern . trd return false unless tld == pattern . tld && sld == pattern . sld matching_pattern? ( pattern ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Controller :: Base ] controller [CODESPLIT] def << ( controller ) options = controller . cli_options unless include? ( controller ) option_parser . add ( options ) if options super ( controller ) end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the threads attribute and update hydra accordinly If the throttle attribute is > 0 max_threads will be forced to 1 [CODESPLIT] def max_threads = ( number ) @max_threads = number . to_i . positive? && throttle . zero? ? number . to_i : 1 hydra . max_concurrency = @max_threads end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Hook to be able to have an exit code returned depending on the findings / errors : nocov : [CODESPLIT] def exit_hook # Avoid hooking the exit when rspec is running, otherwise it will always return 0 # and Travis won't detect failed builds. Couldn't find a better way, even though # some people managed to https://github.com/rspec/rspec-core/pull/410 return if defined? ( RSpec ) at_exit do exit ( run_error_exit_code ) if run_error # The parsed_option[:url] must be checked to avoid raising erros when only -h/-v are given exit ( NS :: ExitCode :: VULNERABLE ) if NS :: ParsedCli . url && controllers . first . target . vulnerable? exit ( NS :: ExitCode :: OK ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nocov : [CODESPLIT] def run_error_exit_code return NS :: ExitCode :: CLI_OPTION_ERROR if run_error . is_a? ( OptParseValidator :: Error ) || run_error . is_a? ( OptionParser :: ParseError ) return NS :: ExitCode :: INTERRUPTED if run_error . is_a? ( Interrupt ) return NS :: ExitCode :: ERROR if run_error . is_a? ( NS :: Error :: Standard ) || run_error . is_a? ( CMSScanner :: Error :: Standard ) NS :: ExitCode :: EXCEPTION end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if the remote website is up . [CODESPLIT] def online? ( path = nil ) NS :: Browser . get ( url ( path ) ) . code . nonzero? ? true : false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] url [CODESPLIT] def redirection ( url = nil ) url ||= @uri . to_s return unless [ 301 , 302 ] . include? ( NS :: Browser . get ( url ) . code ) res = NS :: Browser . get ( url , followlocation : true ) res . effective_url == url ? nil : res . effective_url end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a HEAD request to the path provided then if its response code is in the array of codes given a GET is done and the response returned . Otherwise the HEAD response is returned . [CODESPLIT] def head_and_get ( path , codes = [ 200 ] , params = { } ) url_to_get = url ( path ) head_params = ( params [ :head ] || { } ) . merge ( head_or_get_params ) head_res = NS :: Browser . forge_request ( url_to_get , head_params ) . run codes . include? ( head_res . code ) ? NS :: Browser . get ( url_to_get , params [ :get ] || { } ) : head_res end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a connection to the database [CODESPLIT] def db return @db unless @db . nil? Sequel . single_threaded = true @db = Sequel . connect ( config ( :sql_url ) , :encoding => 'utf8' ) #@db.loggers << Logger.new(STDOUT) if @db . tables . empty? dir = File . join ( File . dirname ( __FILE__ ) , 'migrations' ) puts \"Database empty, running migrations from #{dir}\" Sequel . extension :migration Sequel :: Migrator . apply ( @db , dir ) end @db end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure a commit exists [CODESPLIT] def ensure_commit ( repo , sha , user , comments = true ) ensure_repo ( user , repo ) c = retrieve_commit ( repo , sha , user ) if c . nil? warn \"Commit #{user}/#{repo} -> #{sha} does not exist\" return end stored = store_commit ( c , repo , user ) ensure_parents ( c ) if not c [ 'commit' ] [ 'comment_count' ] . nil? and c [ 'commit' ] [ 'comment_count' ] > 0 ensure_commit_comments ( user , repo , sha ) if comments end ensure_repo_commit ( user , repo , sha ) stored end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve commits for a repository starting from + sha + == Parameters : [ user ] The user to whom the repo belongs . [ repo ] The repo to look for commits into . [ sha ] The first commit to start retrieving from . If nil then retrieval starts from what the project considers as master branch . [ return_retrieved ] Should retrieved commits be returned? If not memory is saved while processing them . [ num_commits ] Number of commit to retrieve [ fork_all ] Retrieve all commits even if a repo is a fork [CODESPLIT] def ensure_commits ( user , repo , sha : nil , return_retrieved : false , num_commits : - 1 , fork_all : false ) currepo = ensure_repo ( user , repo ) unless currepo [ :forked_from ] . nil? or fork_all r = retrieve_repo ( user , repo ) return if r . nil? parent_owner = r [ 'parent' ] [ 'owner' ] [ 'login' ] parent_repo = r [ 'parent' ] [ 'name' ] ensure_fork_commits ( user , repo , parent_owner , parent_repo ) return end num_retrieved = 0 commits = [ 'foo' ] # Dummy entry for simplifying the loop below commit_acc = [ ] until commits . empty? commits = retrieve_commits ( repo , sha , user , 1 ) # This means that we retrieved the last commit page again if commits . size == 1 and commits [ 0 ] [ 'sha' ] == sha commits = [ ] end retrieved = commits . map do | c | sha = c [ 'sha' ] save { ensure_commit ( repo , c [ 'sha' ] , user ) } end # Store retrieved commits to return, if client requested so if return_retrieved commit_acc = commit_acc << retrieved end num_retrieved += retrieved . size if num_commits > 0 and num_retrieved >= num_commits break end end commit_acc . flatten . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the parents for a specific commit . The commit must be first stored in the database . [CODESPLIT] def ensure_parents ( commit ) commits = db [ :commits ] parents = db [ :commit_parents ] commit [ 'parents' ] . map do | p | save do url = p [ 'url' ] . split ( / \\/ / ) this = commits . first ( :sha => commit [ 'sha' ] ) parent = commits . first ( :sha => url [ 7 ] ) if parent . nil? c = retrieve_commit ( url [ 5 ] , url [ 7 ] , url [ 4 ] ) if c . nil? warn \"Could not retrieve commit_parent #{url[4]}/#{url[5]} -> #{url[7]} to #{this[:sha]}\" next end parent = store_commit ( c , url [ 5 ] , url [ 4 ] ) end if parent . nil? warn \"Could not find #{url[4]}/#{url[5]} -> #{url[7]}, parent to commit #{this[:sha]}\" next end if parents . first ( :commit_id => this [ :id ] , :parent_id => parent [ :id ] ) . nil? parents . insert ( :commit_id => this [ :id ] , :parent_id => parent [ :id ] ) info \"Added commit_parent #{parent[:sha]} to commit #{this[:sha]}\" else debug \"Parent #{parent[:sha]} for commit #{this[:sha]} exists\" end parents . first ( :commit_id => this [ :id ] , :parent_id => parent [ :id ] ) end end . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that a commit has been associated with the provided repo == Parameters : [ user ] The user that owns the repo this commit has been submitted to [ repo ] The repo receiving the commit [ sha ] The commit SHA [CODESPLIT] def ensure_repo_commit ( user , repo , sha ) project = ensure_repo ( user , repo ) if project . nil? warn \"Repo #{user}/#{repo} does not exist\" return end commitid = db [ :commits ] . first ( :sha => sha ) [ :id ] exists = db [ :project_commits ] . first ( :project_id => project [ :id ] , :commit_id => commitid ) if exists . nil? db [ :project_commits ] . insert ( :project_id => project [ :id ] , :commit_id => commitid ) info \"Added commit_assoc #{sha} with #{user}/#{repo}\" db [ :project_commits ] . first ( :project_id => project [ :id ] , :commit_id => commitid ) else debug \"Association of commit #{sha} with repo #{user}/#{repo} exists\" exists end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add ( or update ) an entry for a commit author . This method uses information in the JSON object returned by Github to add ( or update ) a user in the metadata database with a full user entry ( both Git and Github details ) . [CODESPLIT] def commit_user ( githubuser , commituser ) users = db [ :users ] name = commituser [ 'name' ] email = commituser [ 'email' ] #if is_valid_email(commituser['email']) # Github user can be null when the commit email has not been associated # with any account in Github. login = githubuser [ 'login' ] unless githubuser . nil? # web-flow is a special user reserved for web-based commits: # https://api.github.com/users/web-flow # We do not follow the process below as this user's email # (noreply@github.com) clashes other existing users' emails. if login == 'web-flow' return ensure_user_byuname ( 'web-flow' ) end return ensure_user ( \"#{name}<#{email}>\" , false , false ) if login . nil? dbuser = users . first ( :login => login ) byemail = users . first ( :email => email ) if dbuser . nil? # We do not have the user in the database yet added = ensure_user ( login , false , false ) # A commit user can be found by email but not # by the user name he used to commit. This probably means that the # user has probably changed his user name. Treat the user's by-email # description as valid. if added . nil? and not byemail . nil? warn \"Found user #{byemail[:login]} with same email #{email} as non existing user #{login}. Assigning user #{login} to #{byemail[:login]}\" return users . first ( :login => byemail [ :login ] ) end # This means that the user's login has been associated with a # Github user by the time the commit was done (and hence Github was # able to associate the commit to an account), but afterwards the # user has deleted his account (before GHTorrent processed it). # On absense of something better to do, try to find the user by email # and return a \"fake\" user entry. if added . nil? warn \"User account for user #{login} deleted from Github\" return ensure_user ( \"#{name}<#{email}>\" , false , false ) end if byemail . nil? users . filter ( :login => login ) . update ( :name => name ) if added [ :name ] . nil? users . filter ( :login => login ) . update ( :email => email ) if added [ :email ] . nil? else # There is a previous entry for the user, currently identified by # email. This means that the user has updated his account and now # Github is able to associate his commits with his git credentials. # As the previous entry might have already associated records, just # delete the new one and update the existing with any extra data. users . filter ( :login => login ) . delete users . filter ( :email => email ) . update ( :login => login , :company => added [ :company ] , :location => added [ :location ] , :created_at => added [ :created_at ] ) end else users . filter ( :login => login ) . update ( :name => name ) if dbuser [ :name ] . nil? users . filter ( :login => login ) . update ( :email => email ) if dbuser [ :email ] . nil? end users . first ( :login => login ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that a user exists or fetch its latest state from Github == Parameters : [ user ] The full email address in RFC 822 format or a login name to lookup the user by [ followers ] A boolean value indicating whether to retrieve the user s followers [ orgs ] A boolean value indicating whether to retrieve the organizations the user participates into == Returns : If the user can be retrieved it is returned as a Hash . Otherwise the result is nil [CODESPLIT] def ensure_user ( user , followers = true , orgs = true ) # Github only supports alpa-nums and dashes in its usernames. # All other sympbols are treated as emails. if not user . match ( / \\w \\- / ) begin name , email = user . split ( \"<\" ) email = email . split ( \">\" ) [ 0 ] name = name . strip unless name . nil? email = email . strip unless email . nil? rescue StandardError warn \"Not a valid email address: #{user}\" return end unless is_valid_email ( email ) warn \"Extracted email(#{email}) not valid for user #{user}\" end u = ensure_user_byemail ( email , name ) else u = ensure_user_byuname ( user ) ensure_user_followers ( user ) if followers ensure_orgs ( user ) if orgs end return u end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that a user exists or fetch its latest state from Github == Parameters : user :: The login name to lookup the user by [CODESPLIT] def ensure_user_byuname ( user ) users = db [ :users ] usr = users . first ( :login => user ) if usr . nil? u = retrieve_user_byusername ( user ) if u . nil? warn \"User #{user} does not exist\" return end email = unless u [ 'email' ] . nil? if u [ 'email' ] . strip == '' then nil else u [ 'email' ] . strip end end geo = geolocate ( location : u [ 'location' ] ) users . insert ( :login => u [ 'login' ] , :name => u [ 'name' ] , :company => u [ 'company' ] , :email => email , :fake => false , :deleted => false , :type => user_type ( u [ 'type' ] ) , :long => geo [ :long ] , :lat => geo [ :lat ] , :country_code => geo [ :country_code ] , :state => geo [ :state ] , :city => geo [ :city ] , :created_at => date ( u [ 'created_at' ] ) ) info \"Added user #{user}\" if user_type ( u [ 'type' ] ) == 'ORG' info \"User #{user} is an organization. Retrieving members\" ensure_org ( u [ 'login' ] , true ) end users . first ( :login => user ) else debug \"User #{user} exists\" usr end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all followers for a user . Since we do not know when the actual follow event took place we set the created_at field to the timestamp of the method call . [CODESPLIT] def ensure_user_followers ( followed ) curuser = ensure_user ( followed , false , false ) followers = db . from ( :followers , :users ) . where ( Sequel . qualify ( 'followers' , 'follower_id' ) => Sequel . qualify ( 'users' , 'id' ) ) . where ( Sequel . qualify ( 'followers' , 'user_id' ) => curuser [ :id ] ) . select ( :login ) . all retrieve_user_followers ( followed ) . reduce ( [ ] ) do | acc , x | if followers . find { | y | y [ :login ] == x [ 'login' ] } . nil? acc << x else acc end end . map { | x | save { ensure_user_follower ( followed , x [ 'login' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that a user follows another one [CODESPLIT] def ensure_user_follower ( followed , follower , date_added = nil ) follower_user = ensure_user ( follower , false , false ) followed_user = ensure_user ( followed , false , false ) if followed_user . nil? or follower_user . nil? warn \"Could not find follower #{follower} or user #{followed}\" return end followers = db [ :followers ] follower_id = follower_user [ :id ] followed_id = followed_user [ :id ] follower_exists = followers . first ( :user_id => followed_id , :follower_id => follower_id ) if follower_exists . nil? added = if date_added . nil? max ( follower_user [ :created_at ] , followed_user [ :created_at ] ) else date_added end retrieved = retrieve_user_follower ( followed , follower ) if retrieved . nil? warn \"Could not retrieve follower #{follower} for #{followed}\" return end followers . insert ( :user_id => followed_id , :follower_id => follower_id , :created_at => added ) info \"Added follower #{follower} to #{followed}\" else debug \"Follower #{follower} for user #{followed} exists\" end unless date_added . nil? followers . filter ( :user_id => followed_id , :follower_id => follower_id ) . update ( :created_at => date ( date_added ) ) info \"Updated follower #{followed} -> #{follower}, created_at -> #{date(date_added)}\" end followers . first ( :user_id => followed_id , :follower_id => follower_id ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try to retrieve a user by email . Search the DB first fall back to Github search API if unsuccessful . [CODESPLIT] def ensure_user_byemail ( email , name ) users = db [ :users ] usr = users . first ( :email => email ) if usr . nil? u = retrieve_user_byemail ( email , name ) if u . nil? or u [ 'login' ] . nil? warn \"Could not retrieve user #{email} through search API query\" login = ( 0 ... 8 ) . map { 65 . + ( rand ( 25 ) ) . chr } . join users . insert ( :email => email , :name => name , :login => login , :fake => true , :deleted => false , :created_at => Time . now ) info \"Added user fake #{login} -> #{email}\" users . first ( :login => login ) else in_db = users . first ( :login => u [ 'login' ] ) geo = geolocate ( location : u [ 'location' ] ) if in_db . nil? users . insert ( :login => u [ 'login' ] , :name => u [ 'name' ] , :company => u [ 'company' ] , :email => u [ 'email' ] , :long => geo [ :long ] , :lat => geo [ :lat ] , :country_code => geo [ :country_code ] , :state => geo [ :state ] , :city => geo [ :city ] , :fake => false , :deleted => false , :created_at => date ( u [ 'created_at' ] ) ) info \"Added user #{u['login']} (#{email}) through search API query\" else in_db . update ( :name => u [ 'name' ] , :company => u [ 'company' ] , :email => u [ 'email' ] , :long => geo [ :long ] , :lat => geo [ :lat ] , :country_code => geo [ :country_code ] , :state => geo [ :state ] , :city => geo [ :city ] , :fake => false , :deleted => false , :created_at => date ( u [ 'created_at' ] ) ) debug \"User #{u['login']} with email #{email} exists\" end users . first ( :login => u [ 'login' ] ) end else debug \"User with email #{email} exists\" usr end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that a repo exists or fetch its latest state from Github [CODESPLIT] def ensure_repo ( user , repo , recursive = false ) repos = db [ :projects ] curuser = ensure_user ( user , false , false ) if curuser . nil? warn \"Could not find user #{user}\" return end currepo = repos . first ( :owner_id => curuser [ :id ] , :name => repo ) unless currepo . nil? debug \"Repo #{user}/#{repo} exists\" return refresh_repo ( user , repo , currepo ) end r = retrieve_repo ( user , repo , true ) if r . nil? warn \"Could not retrieve repo #{user}/#{repo}\" return end if r [ 'owner' ] [ 'login' ] != curuser [ :login ] info \"Repo changed owner from #{curuser[:login]} to #{r['owner']['login']}\" curuser = ensure_user ( r [ 'owner' ] [ 'login' ] , false , false ) end repos . insert ( :url => r [ 'url' ] , :owner_id => curuser [ :id ] , :name => r [ 'name' ] , :description => unless r [ 'description' ] . nil? then r [ 'description' ] [ 0 .. 254 ] else nil end , :language => r [ 'language' ] , :created_at => date ( r [ 'created_at' ] ) , :updated_at => date ( Time . now ) , :etag => unless r [ 'etag' ] . nil? then r [ 'etag' ] end ) unless r [ 'parent' ] . nil? parent_owner = r [ 'parent' ] [ 'owner' ] [ 'login' ] parent_repo = r [ 'parent' ] [ 'name' ] parent = ensure_repo ( parent_owner , parent_repo ) if parent . nil? warn \"Could not find repo #{parent_owner}/#{parent_repo}, parent of: #{user}/#{repo}\" repos . filter ( :owner_id => curuser [ :id ] , :name => repo ) . update ( :forked_from => - 1 ) else repos . filter ( :owner_id => curuser [ :id ] , :name => repo ) . update ( :forked_from => parent [ :id ] ) info \"Repo #{user}/#{repo} is a fork of #{parent_owner}/#{parent_repo}\" unless ensure_fork_point ( user , repo ) . nil? warn \"Could not find fork point for #{user}/#{repo}, fork of #{parent_owner}/#{parent_repo}\" end end end if recursive and not ensure_repo_recursive ( user , repo ) warn \"Could retrieve #{user}/#{repo} recursively\" return nil end info \"Added repo #{user}/#{repo}\" return repos . first ( :owner_id => curuser [ :id ] , :name => repo ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details about the languages used in the repository [CODESPLIT] def ensure_languages ( owner , repo ) currepo = ensure_repo ( owner , repo ) langs = retrieve_languages ( owner , repo ) if langs . nil? or langs . empty? warn \"Could not find languages for repo #{owner}/#{repo}\" return end ts = Time . now langs . keys . each do | lang | db [ :project_languages ] . insert ( :project_id => currepo [ :id ] , :language => lang . downcase , :bytes => langs [ lang ] , :created_at => ts ) info \"Added project_language #{owner}/#{repo} -> #{lang} (#{langs[lang]} bytes)\" end db [ :project_languages ] . where ( :project_id => currepo [ :id ] ) . where ( :created_at => ts ) . all end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fast path to project forking . Retrieve all commits page by page until we reach a commit that has been registered with the parent repository . Then copy all remaining parent commits to this repo . [CODESPLIT] def ensure_fork_commits ( owner , repo , parent_owner , parent_repo ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repo #{owner}/#{repo}\" return end parent = ensure_repo ( parent_owner , parent_repo ) if parent . nil? warn \"Could not find repo #{parent_owner}/#{parent_repo}, parent of #{owner}/#{repo}\" return end strategy = case when config ( :fork_commits ) . match ( / /i ) :all when config ( :fork_commits ) . match ( / /i ) :fork_point when config ( :fork_commits ) . match ( / /i ) :none else :fork_point end fork_commit = ensure_fork_point ( owner , repo ) if fork_commit . nil? or fork_commit . empty? warn \"Could not find fork commit for repo #{owner}/#{repo}. Retrieving all commits.\" return ensure_commits ( owner , repo , fork_all : true ) end debug \"Retrieving commits for fork #{owner}/#{repo}: strategy is #{strategy}\" return if strategy == :none if strategy == :fork_point # Retrieve commits up to fork point (fork_commit strategy) info \"Retrieving commits for #{owner}/#{repo} until fork commit #{fork_commit[:sha]}\" master_branch = retrieve_default_branch ( parent_owner , parent_repo ) return if master_branch . nil? sha = master_branch found = false while not found commits = retrieve_commits ( repo , sha , owner , 1 ) # This means that we retrieved no commits if commits . size == 0 break end # This means we retrieved the last page again if commits . size == 1 and commits [ 0 ] [ 'sha' ] == sha break end for c in commits ensure_commit ( repo , c [ 'sha' ] , owner ) sha = c [ 'sha' ] if c [ 'sha' ] == fork_commit [ :sha ] found = true break end end end end if strategy == :all shared_commit = db [ :commits ] . first ( :sha => fork_commit ) copied = 0 to_copy = db . from ( :project_commits , :commits ) . where ( Sequel . qualify ( 'project_commits' , 'commit_id' ) => Sequel . qualify ( 'commits' , 'id' ) ) . where ( Sequel . qualify ( 'project_commits' , 'project_id' ) => parent [ :id ] ) . where ( 'commits.created_at < ?' , shared_commit [ :created_at ] ) . select ( Sequel . qualify ( 'commits' , 'id' ) ) to_copy . each do | c | copied += 1 begin db [ :project_commits ] . insert ( :project_id => currepo [ :id ] , :commit_id => c [ :id ] ) debug \"Copied commit #{c[:sha]} #{parent_owner}/#{parent_repo} -> #{owner}/#{repo} (#{copied} total)\" rescue StandardError => e warn \"Could not copy commit #{c[:sha]} #{parent_owner}/#{parent_repo} -> #{owner}/#{repo} : #{e.message}\" end end info \"Finished copying commits from #{parent_owner}/#{parent_repo} -> #{owner}/#{repo}: #{copied} total\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve and return the commit at which the provided fork was forked at [CODESPLIT] def ensure_fork_point ( owner , repo ) fork = ensure_repo ( owner , repo , false ) if fork [ :forked_from ] . nil? warn \"Repo #{owner}/#{repo} is not a fork\" return nil end # Return commit if already specified unless fork [ :forked_commit_id ] . nil? commit = db [ :commits ] . where ( :id => fork [ :forked_commit_id ] ) . first return commit unless commit . nil? end parent = db . from ( :projects , :users ) . where ( Sequel . qualify ( 'projects' , 'owner_id' ) => Sequel . qualify ( 'users' , 'id' ) ) . where ( Sequel . qualify ( 'projects' , 'id' ) => fork [ :forked_from ] ) . select ( Sequel . qualify ( 'users' , 'login' ) , Sequel . qualify ( 'projects' , 'name' ) ) . first if parent . nil? warn \"Unknown parent for repo #{owner}/#{repo}\" return nil end default_branch = retrieve_default_branch ( parent [ :login ] , parent [ :name ] ) # Retrieve diff between parent and fork master branch diff = retrieve_master_branch_diff ( owner , repo , default_branch , parent [ :login ] , parent [ :name ] , default_branch ) if diff . nil? or diff . empty? # Try a bit harder by refreshing the default branch default_branch = retrieve_default_branch ( parent [ :login ] , parent [ :name ] , true ) diff = retrieve_master_branch_diff ( owner , repo , default_branch , parent [ :login ] , parent [ :name ] , default_branch ) end if diff . nil? or diff . empty? # This means that the are no common ancestors between the repos # This can apparently happen when the parent repo was renamed or force-pushed # example: https://github.com/openzipkin/zipkin/compare/master...aa1wi:master warn \"No common ancestor between #{parent[:login]}/#{parent[:name]} and #{owner}/#{repo}\" return nil else debug \"Fork #{owner}/#{repo} is #{diff['ahead_by']} commits ahead and #{diff['behind_by']} commits behind #{parent[:login]}/#{parent[:name]}\" end if diff [ 'ahead_by' ] . to_i > 0 # This means that the fork has diverged, and we need to search through the fork # commit graph for the earliest commit that is shared with the parent. GitHub's # diff contains a list of divergent commits. We are sorting those by date # and select the earliest one. We do date sort instead of graph walking as this # would be prohibetively slow if the commits for the parent did not exist. earliest_diverging = diff [ 'commits' ] . sort_by { | x | x [ 'commit' ] [ 'author' ] [ 'date' ] } . first if earliest_diverging [ 'parents' ] . nil? # this means that the repo was forked from the from the parent repo's initial commit. thus, they both share an initial commit. # example: https://api.github.com/repos/btakita/pain-point/compare/master...spent:master likely_fork_point = ensure_commit ( parent [ :name ] , earliest_diverging [ 'sha' ] , parent [ 'login' ] ) else # Make sure that all likely fork points exist for the parent project # and select the latest of them. # https://github.com/gousiosg/github-mirror/compare/master...pombredanne:master likely_fork_point = earliest_diverging [ 'parents' ] . map { | x | ensure_commit ( parent [ :name ] , x [ 'sha' ] , parent [ :login ] ) } . select { | x | ! x . nil? } . sort_by { | x | x [ :created_at ] } . last end forked_sha = likely_fork_point [ :sha ] else # This means that the fork has not diverged. forked_sha = diff [ 'merge_base_commit' ] [ 'sha' ] end forked_commit = ensure_commit ( repo , forked_sha , owner ) ; debug \"Fork commit for #{owner}/#{repo} is #{forked_sha}\" unless forked_commit . nil? db [ :projects ] . filter ( :id => fork [ :id ] ) . update ( :forked_commit_id => forked_commit [ :id ] ) info \"Repo #{owner}/#{repo} was forked at #{parent[:login]}/#{parent[:name]}:#{forked_sha}\" end db [ :commits ] . where ( :sha => forked_sha ) . first end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that the organizations the user participates into exist [CODESPLIT] def ensure_orgs ( user ) retrieve_orgs ( user ) . map { | o | save { ensure_participation ( user , o [ 'login' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that a user participates to the provided organization [CODESPLIT] def ensure_participation ( user , organization , members = true ) org = ensure_org ( organization , members ) if org . nil? warn \"Could not find organization #{organization}\" return end usr = ensure_user ( user , false , false ) org_members = db [ :organization_members ] participates = org_members . first ( :user_id => usr [ :id ] , :org_id => org [ :id ] ) if participates . nil? org_members . insert ( :user_id => usr [ :id ] , :org_id => org [ :id ] ) info \"Added participation #{organization} -> #{user}\" org_members . first ( :user_id => usr [ :id ] , :org_id => org [ :id ] ) else debug \"Participation #{organization} -> #{user} exists\" participates end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that an organization exists [CODESPLIT] def ensure_org ( organization , members = true ) org = db [ :users ] . first ( :login => organization , :type => 'org' ) if org . nil? org = ensure_user ( organization , false , false ) # Not an organization, don't go ahead if org [ :type ] != 'ORG' warn \"User #{organization} is not an organization\" return nil end end if members retrieve_org_members ( organization ) . map do | x | ensure_participation ( ensure_user ( x [ 'login' ] , false , false ) [ :login ] , organization , false ) end end org end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all comments for a commit [CODESPLIT] def ensure_commit_comments ( user , repo , sha ) commit_id = db [ :commits ] . first ( :sha => sha ) [ :id ] stored_comments = db [ :commit_comments ] . filter ( :commit_id => commit_id ) commit_comments = retrieve_commit_comments ( user , repo , sha ) not_saved = commit_comments . reduce ( [ ] ) do | acc , x | if stored_comments . find { | y | y [ :comment_id ] == x [ 'id' ] } . nil? acc << x else acc end end not_saved . map { | x | save { ensure_commit_comment ( user , repo , sha , x [ 'id' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that all watchers exist for a repository [CODESPLIT] def ensure_watchers ( owner , repo ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving watchers\" return end watchers = db . from ( :watchers , :users ) . where ( Sequel . qualify ( 'watchers' , 'user_id' ) => Sequel . qualify ( 'users' , 'id' ) ) . where ( Sequel . qualify ( 'watchers' , 'repo_id' ) => currepo [ :id ] ) . select ( :login ) . all retrieve_watchers ( owner , repo ) . reduce ( [ ] ) do | acc , x | if watchers . find { | y | y [ :login ] == x [ 'login' ] } . nil? acc << x else acc end end . map { | x | save { ensure_watcher ( owner , repo , x [ 'login' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that a watcher / stargazer exists for a repository [CODESPLIT] def ensure_watcher ( owner , repo , watcher , date_added = nil ) project = ensure_repo ( owner , repo ) new_watcher = ensure_user ( watcher , false , false ) if new_watcher . nil? or project . nil? warn \"Could not find watcher #{watcher} or repo #{owner}/#{repo}\" return end watchers = db [ :watchers ] watcher_exist = watchers . first ( :user_id => new_watcher [ :id ] , :repo_id => project [ :id ] ) retrieved = retrieve_watcher ( owner , repo , watcher ) created_at = case when ( not date_added . nil? ) date ( date_added ) when ( not retrieved . nil? and not retrieved [ 'created_at' ] . nil? ) date ( retrieved [ 'created_at' ] ) else max ( date ( project [ :created_at ] ) , date ( new_watcher [ :created_at ] ) ) end if watcher_exist . nil? if retrieved . nil? warn \"Could not retrieve watcher #{watcher} of repo #{owner}/#{repo}\" return end watchers . insert ( :user_id => new_watcher [ :id ] , :repo_id => project [ :id ] , :created_at => date ( created_at ) ) info \"Added watcher #{owner}/#{repo} -> #{watcher}\" else debug \"Watcher #{owner}/#{repo} -> #{watcher} exists\" end w = watchers . first ( :user_id => new_watcher [ :id ] , :repo_id => project [ :id ] ) if w [ :created_at ] < created_at watchers . filter ( :user_id => new_watcher [ :id ] , :repo_id => project [ :id ] ) . update ( :created_at => date ( created_at ) ) info \"Updated watcher #{owner}/#{repo} -> #{watcher}, created_at -> #{date_added}\" end w end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process all pull requests [CODESPLIT] def ensure_pull_requests ( owner , repo , refresh = false ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving pull requests\" return end raw_pull_reqs = if refresh retrieve_pull_requests ( owner , repo , refresh = true ) else pull_reqs = db [ :pull_requests ] . filter ( :base_repo_id => currepo [ :id ] ) . all retrieve_pull_requests ( owner , repo ) . reduce ( [ ] ) do | acc , x | if pull_reqs . find { | y | y [ :pullreq_id ] == x [ 'number' ] } . nil? acc << x else acc end end end raw_pull_reqs . map { | x | save { ensure_pull_request ( owner , repo , x [ 'number' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a pull request history event [CODESPLIT] def ensure_pull_request_history ( id , ts , act , actor ) user = unless actor . nil? ensure_user ( actor , false , false ) end pull_req_history = db [ :pull_request_history ] entry = if [ 'opened' , 'merged' ] . include? act pull_req_history . first ( :pull_request_id => id , :action => act ) else pull_req_history . first ( :pull_request_id => id , :created_at => ( ts - 3 ) .. ( ts + 3 ) , :action => act ) end if entry . nil? pull_req_history . insert ( :pull_request_id => id , :created_at => ts , :action => act , :actor_id => unless user . nil? then user [ :id ] end ) info \"Added pullreq_event (#{id}) -> (#{act}) by (#{actor}) timestamp #{ts}\" else debug \"Pull request (#{id}) event (#{act}) by (#{actor}) timestamp #{ts} exists\" if entry [ :actor_id ] . nil? and not user . nil? pull_req_history . where ( :pull_request_id => id , :created_at => ( ts - 3 ) .. ( ts + 3 ) , :action => act ) . update ( :actor_id => user [ :id ] ) info \"Updated pull request (#{id}) event (#{act}) timestamp #{ts}, actor -> #{user[:login]}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks whether a pull request concerns two branches of the same repository [CODESPLIT] def pr_is_intra_branch ( req ) return false unless pr_has_head_repo ( req ) if req [ 'head' ] [ 'repo' ] [ 'owner' ] [ 'login' ] == req [ 'base' ] [ 'repo' ] [ 'owner' ] [ 'login' ] and req [ 'head' ] [ 'repo' ] [ 'full_name' ] == req [ 'base' ] [ 'repo' ] [ 'full_name' ] true else false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Produces a log message [CODESPLIT] def pr_log_msg ( req ) head = if pr_has_head_repo ( req ) req [ 'head' ] [ 'repo' ] [ 'full_name' ] else '(head deleted)' end <<-eos . gsub ( / \\s / , ' ' ) . strip #{ req [ 'number' ] } #{ head } #{ req [ 'base' ] [ 'repo' ] [ 'full_name' ] } eos end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process a pull request [CODESPLIT] def ensure_pull_request ( owner , repo , pullreq_id , comments = true , commits = true , history = true , state = nil , actor = nil , created_at = nil ) pulls_reqs = db [ :pull_requests ] project = ensure_repo ( owner , repo ) if project . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving pull request #{pullreq_id}\" return end retrieved = retrieve_pull_request ( owner , repo , pullreq_id ) if retrieved . nil? warn \"Could not retrieve pull_req #{owner}/#{repo} -> #{pullreq_id}\" return end base_repo = ensure_repo ( retrieved [ 'base' ] [ 'repo' ] [ 'owner' ] [ 'login' ] , retrieved [ 'base' ] [ 'repo' ] [ 'name' ] ) base_commit = ensure_commit ( retrieved [ 'base' ] [ 'repo' ] [ 'name' ] , retrieved [ 'base' ] [ 'sha' ] , retrieved [ 'base' ] [ 'repo' ] [ 'owner' ] [ 'login' ] ) if pr_is_intra_branch ( retrieved ) head_repo = base_repo head_commit = ensure_commit ( retrieved [ 'base' ] [ 'repo' ] [ 'name' ] , retrieved [ 'head' ] [ 'sha' ] , retrieved [ 'base' ] [ 'repo' ] [ 'owner' ] [ 'login' ] ) debug pr_log_msg ( retrieved ) + ' is intra-branch' else head_repo = if pr_has_head_repo ( retrieved ) ensure_repo ( retrieved [ 'head' ] [ 'repo' ] [ 'owner' ] [ 'login' ] , retrieved [ 'head' ] [ 'repo' ] [ 'name' ] ) end head_commit = if not head_repo . nil? ensure_commit ( retrieved [ 'head' ] [ 'repo' ] [ 'name' ] , retrieved [ 'head' ] [ 'sha' ] , retrieved [ 'head' ] [ 'repo' ] [ 'owner' ] [ 'login' ] ) end end pull_req_user = ensure_user ( retrieved [ 'user' ] [ 'login' ] , false , false ) merged = if retrieved [ 'merged_at' ] . nil? then false else true end closed = if retrieved [ 'closed_at' ] . nil? then false else true end pull_req = pulls_reqs . first ( :base_repo_id => project [ :id ] , :pullreq_id => pullreq_id ) if pull_req . nil? pulls_reqs . insert ( :head_repo_id => if not head_repo . nil? then head_repo [ :id ] end , :base_repo_id => if not base_repo . nil? then base_repo [ :id ] end , :head_commit_id => if not head_commit . nil? then head_commit [ :id ] end , :base_commit_id => if not base_commit . nil? then base_commit [ :id ] end , :pullreq_id => pullreq_id , :intra_branch => pr_is_intra_branch ( retrieved ) ) info 'Added ' + pr_log_msg ( retrieved ) else debug pr_log_msg ( retrieved ) + ' exists' end pull_req = pulls_reqs . first ( :base_repo_id => project [ :id ] , :pullreq_id => pullreq_id ) # Add a fake (or not so fake) issue in the issues table to serve # as root for retrieving discussion comments for this pull request issues = db [ :issues ] issue = issues . first ( :pull_request_id => pull_req [ :id ] ) if issue . nil? issues . insert ( :repo_id => base_repo [ :id ] , :assignee_id => nil , :reporter_id => nil , :issue_id => pullreq_id , :pull_request => true , :pull_request_id => pull_req [ :id ] , :created_at => date ( retrieved [ 'created_at' ] ) ) debug 'Added accompanying_issue for ' + pr_log_msg ( retrieved ) else debug 'Accompanying issue for ' + pr_log_msg ( retrieved ) + ' exists' end if history # Actions on pull requests opener = pull_req_user [ :login ] ensure_pull_request_history ( pull_req [ :id ] , date ( retrieved [ 'created_at' ] ) , 'opened' , opener ) merger = if retrieved [ 'merged_by' ] . nil? then actor else retrieved [ 'merged_by' ] [ 'login' ] end ensure_pull_request_history ( pull_req [ :id ] , date ( retrieved [ 'merged_at' ] ) , 'merged' , merger ) if ( merged && state != 'merged' ) closer = if merged then merger else actor end ensure_pull_request_history ( pull_req [ :id ] , date ( retrieved [ 'closed_at' ] ) , 'closed' , closer ) if ( closed && state != 'closed' ) ensure_pull_request_history ( pull_req [ :id ] , date ( created_at ) , state , actor ) unless state . nil? end ensure_pull_request_commits ( owner , repo , pullreq_id , pull_req , retrieved ) if commits ensure_pullreq_comments ( owner , repo , pullreq_id , pull_req ) if comments ensure_issue_comments ( owner , repo , pullreq_id , pull_req [ :id ] ) if comments pull_req end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all forks for a project . [CODESPLIT] def ensure_forks ( owner , repo ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving forks\" return end existing_forks = db . from ( :projects , :users ) . where ( Sequel . qualify ( 'users' , 'id' ) => Sequel . qualify ( 'projects' , 'owner_id' ) ) . where ( Sequel . qualify ( 'projects' , 'forked_from' ) => currepo [ :id ] ) . select ( Sequel . qualify ( 'projects' , 'name' ) , :login ) . all retrieve_forks ( owner , repo ) . reduce ( [ ] ) do | acc , x | if existing_forks . find do | y | forked_repo_owner = x [ 'url' ] . split ( / \\/ / ) [ 4 ] forked_repo_name = x [ 'url' ] . split ( / \\/ / ) [ 5 ] y [ :login ] == forked_repo_owner && y [ :name ] == forked_repo_name end . nil? acc << x else acc end end . map { | x | save { ensure_fork ( owner , repo , x [ 'id' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that a fork is retrieved for a project [CODESPLIT] def ensure_fork ( owner , repo , fork_id ) fork = retrieve_fork ( owner , repo , fork_id ) if fork . nil? warn \"Could not retrieve fork #{owner}/#{repo} -> #{fork_id}\" return end fork_name = if fork [ 'full_name' ] . nil? then fork [ 'url' ] . split ( / \\/ / ) [ 4 .. 5 ] . join ( '/' ) else fork [ 'full_name' ] end fork_owner = fork_name . split ( / \\/ / ) [ 0 ] fork_name = fork_name . split ( / \\/ / ) [ 1 ] r = ensure_repo ( fork_owner , fork_name , true ) if r . nil? warn \"Could not add #{fork_owner}/#{fork_name} as fork of #{owner}/#{repo}\" else info \"Added fork #{fork_owner}/#{fork_name} of #{owner}/#{repo}\" end r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure all issues exist for a project [CODESPLIT] def ensure_issues ( owner , repo ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving issues\" return end issues = db [ :issues ] . filter ( :repo_id => currepo [ :id ] ) . all raw_issues = retrieve_issues ( owner , repo ) . reduce ( [ ] ) do | acc , x | if issues . find { | y | y [ :issue_id ] == x [ 'number' ] } . nil? acc << x else acc end end raw_issues . map { | x | save { ensure_issue ( owner , repo , x [ 'number' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make sure that the issue exists [CODESPLIT] def ensure_issue ( owner , repo , issue_id , events = true , comments = true , labels = true ) issues = db [ :issues ] repository = ensure_repo ( owner , repo ) if repository . nil? warn \"Could not find repo #{owner}/#{repo} for retrieving issue #{issue_id}\" return end cur_issue = issues . first ( :issue_id => issue_id , :repo_id => repository [ :id ] ) retrieved = retrieve_issue ( owner , repo , issue_id ) if retrieved . nil? warn \"Could not retrieve issue #{owner}/#{repo} -> #{issue_id}\" return end # Pull requests and issues share the same issue_id pull_req = unless retrieved [ 'pull_request' ] . nil? or retrieved [ 'pull_request' ] [ 'patch_url' ] . nil? debug \"Issue #{owner}/#{repo}->#{issue_id} is a pull request\" ensure_pull_request ( owner , repo , issue_id , false , false , false ) end if cur_issue . nil? reporter = ensure_user ( retrieved [ 'user' ] [ 'login' ] , false , false ) assignee = unless retrieved [ 'assignee' ] . nil? ensure_user ( retrieved [ 'assignee' ] [ 'login' ] , false , false ) end issues . insert ( :repo_id => repository [ :id ] , :assignee_id => unless assignee . nil? then assignee [ :id ] end , :reporter_id => reporter [ :id ] , :issue_id => issue_id , :pull_request => if pull_req . nil? then false else true end , :pull_request_id => unless pull_req . nil? then pull_req [ :id ] end , :created_at => date ( retrieved [ 'created_at' ] ) ) info \"Added issue #{owner}/#{repo} -> #{issue_id}\" else debug \"Issue #{owner}/#{repo}->#{issue_id} exists\" if cur_issue [ :pull_request ] == false and not pull_req . nil? info \"Updated issue #{owner}/#{repo}->#{issue_id} as pull request\" issues . filter ( :issue_id => issue_id , :repo_id => repository [ :id ] ) . update ( :pull_request => true , :pull_request_id => pull_req [ :id ] ) end end ensure_issue_events ( owner , repo , issue_id ) if events ensure_issue_comments ( owner , repo , issue_id ) if comments ensure_issue_labels ( owner , repo , issue_id ) if labels issues . first ( :issue_id => issue_id , :repo_id => repository [ :id ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve and process all events for an issue [CODESPLIT] def ensure_issue_events ( owner , repo , issue_id ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repository #{owner}/#{repo} for retrieving events for issue #{issue_id}\" return end issue = ensure_issue ( owner , repo , issue_id , false , false , false ) if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving events\" return end retrieve_issue_events ( owner , repo , issue_id ) . reduce ( [ ] ) do | acc , x | if db [ :issue_events ] . first ( :issue_id => issue [ :id ] , :event_id => x [ 'id' ] ) . nil? acc << x else acc end end . map { | x | save { ensure_issue_event ( owner , repo , issue_id , x [ 'id' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve and process + event_id + for an + issue_id + [CODESPLIT] def ensure_issue_event ( owner , repo , issue_id , event_id ) issue = ensure_issue ( owner , repo , issue_id , false , false , false ) if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving event #{event_id}\" return end issue_event_str = \"#{owner}/#{repo} -> #{issue_id}/#{event_id}\" curevent = db [ :issue_events ] . first ( :issue_id => issue [ :id ] , :event_id => event_id ) if curevent . nil? retrieved = retrieve_issue_event ( owner , repo , issue_id , event_id ) if retrieved . nil? warn \"Could not retrieve issue_event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}\" return elsif retrieved [ 'actor' ] . nil? warn \"Could not find issue_event_actor #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}\" return end actor = ensure_user ( retrieved [ 'actor' ] [ 'login' ] , false , false ) action_specific = case retrieved [ 'event' ] when \"referenced\" then retrieved [ 'commit_id' ] when \"merged\" then retrieved [ 'commit_id' ] when \"closed\" then retrieved [ 'commit_id' ] else nil end if retrieved [ 'event' ] == 'assigned' def update_assignee ( owner , repo , issue , actor ) db [ :issues ] . first ( :id => issue [ :id ] ) . update ( :assignee_id => actor [ :id ] ) info \"Updated #{owner}/#{repo} -> #{issue[:id]}, assignee -> #{actor[:id]}\" end if issue [ :assignee_id ] . nil? then update_assignee ( owner , repo , issue , actor ) else existing = db [ :issue_events ] . filter ( :issue_id => issue [ :id ] , :action => 'assigned' ) . order ( Sequel . desc ( :created_at ) ) . first if existing . nil? update_assignee ( owner , repo , issue , actor ) elsif date ( existing [ :created_at ] ) < date ( retrieved [ 'created_at' ] ) update_assignee ( owner , repo , issue , actor ) end end end db [ :issue_events ] . insert ( :event_id => event_id , :issue_id => issue [ :id ] , :actor_id => unless actor . nil? then actor [ :id ] end , :action => retrieved [ 'event' ] , :action_specific => action_specific , :created_at => date ( retrieved [ 'created_at' ] ) ) info \"Added issue_event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}\" db [ :issue_events ] . first ( :issue_id => issue [ :id ] , :event_id => event_id ) else debug \"Issue event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str} exists\" curevent end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve and process all comments for an issue . If pull_req_id is not nil this means that we are only retrieving comments for the pull request discussion for projects that don t have issues enabled [CODESPLIT] def ensure_issue_comments ( owner , repo , issue_id , pull_req_id = nil ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find repository #{owner}/#{repo} for retrieving issue comments for issue #{issue_id}\" return end issue = if pull_req_id . nil? ensure_issue ( owner , repo , issue_id , false , false , false ) else db [ :issues ] . first ( :pull_request_id => pull_req_id ) end if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving issue comments\" return end retrieve_issue_comments ( owner , repo , issue_id ) . reduce ( [ ] ) do | acc , x | if db [ :issue_comments ] . first ( :issue_id => issue [ :id ] , :comment_id => x [ 'id' ] ) . nil? acc << x else acc end end . map { | x | save { ensure_issue_comment ( owner , repo , issue_id , x [ 'id' ] , pull_req_id ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve and process + comment_id + for an + issue_id + [CODESPLIT] def ensure_issue_comment ( owner , repo , issue_id , comment_id , pull_req_id = nil ) issue = if pull_req_id . nil? ensure_issue ( owner , repo , issue_id , false , false , false ) else db [ :issues ] . first ( :pull_request_id => pull_req_id ) end if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving comment #{comment_id}\" return end issue_comment_str = \"#{owner}/#{repo} -> #{issue_id}/#{comment_id}\" curcomment = db [ :issue_comments ] . first ( :issue_id => issue [ :id ] , :comment_id => comment_id ) if curcomment . nil? retrieved = retrieve_issue_comment ( owner , repo , issue_id , comment_id ) if retrieved . nil? warn \"Could not retrieve issue_comment #{issue_comment_str}\" return end user = ensure_user ( retrieved [ 'user' ] [ 'login' ] , false , false ) db [ :issue_comments ] . insert ( :comment_id => comment_id , :issue_id => issue [ :id ] , :user_id => unless user . nil? then user [ :id ] end , :created_at => date ( retrieved [ 'created_at' ] ) ) info \"Added issue_comment #{issue_comment_str}\" db [ :issue_comments ] . first ( :issue_id => issue [ :id ] , :comment_id => comment_id ) else debug \"Issue comment #{issue_comment_str} exists\" curcomment end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve repository issue labels [CODESPLIT] def ensure_labels ( owner , repo ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find #{owner}/#{repo} for retrieving issue labels\" return end repo_labels = db [ :repo_labels ] . filter ( :repo_id => currepo [ :id ] ) . all retrieve_repo_labels ( owner , repo ) . reduce ( [ ] ) do | acc , x | if repo_labels . find { | y | y [ :name ] == x [ 'name' ] } . nil? acc << x else acc end end . map { | x | save { ensure_repo_label ( owner , repo , x [ 'name' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a single repository issue label by name [CODESPLIT] def ensure_repo_label ( owner , repo , name ) currepo = ensure_repo ( owner , repo ) if currepo . nil? warn \"Could not find #{owner}/#{repo} for retrieving label #{name}\" return end label = db [ :repo_labels ] . first ( :repo_id => currepo [ :id ] , :name => name ) if label . nil? retrieved = retrieve_repo_label ( owner , repo , name ) if retrieved . nil? warn \"Could not retrieve repo_label #{owner}/#{repo} -> #{name}\" return end db [ :repo_labels ] . insert ( :repo_id => currepo [ :id ] , :name => name ) info \"Added repo_label #{owner}/#{repo} -> #{name}\" db [ :repo_labels ] . first ( :repo_id => currepo [ :id ] , :name => name ) else label end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that all labels have been assigned to the issue [CODESPLIT] def ensure_issue_labels ( owner , repo , issue_id ) issue = ensure_issue ( owner , repo , issue_id , false , false , false ) if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} for retrieving labels\" return end issue_labels = db . from ( :issue_labels , :repo_labels ) . where ( Sequel . qualify ( 'issue_labels' , 'label_id' ) => Sequel . qualify ( 'repo_labels' , 'id' ) ) . where ( Sequel . qualify ( 'issue_labels' , 'issue_id' ) => issue [ :id ] ) . select ( Sequel . qualify ( 'repo_labels' , 'name' ) ) . all retrieve_issue_labels ( owner , repo , issue_id ) . reduce ( [ ] ) do | acc , x | if issue_labels . find { | y | y [ :name ] == x [ 'name' ] } . nil? acc << x else acc end end . map { | x | save { ensure_issue_label ( owner , repo , issue [ :issue_id ] , x [ 'name' ] ) } } . select { | x | ! x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that a specific label has been assigned to the issue [CODESPLIT] def ensure_issue_label ( owner , repo , issue_id , name ) issue = ensure_issue ( owner , repo , issue_id , false , false , false ) if issue . nil? warn \"Could not find issue #{owner}/#{repo} -> #{issue_id} to assign label #{name}\" return end label = ensure_repo_label ( owner , repo , name ) if label . nil? warn \"Could not find repo label #{owner}/#{repo} -> #{name}\" return end issue_lbl = db [ :issue_labels ] . first ( :label_id => label [ :id ] , :issue_id => issue [ :id ] ) if issue_lbl . nil? db [ :issue_labels ] . insert ( :label_id => label [ :id ] , :issue_id => issue [ :id ] , ) info \"Added issue_label #{name} to issue #{owner}/#{repo} -> #{issue_id}\" db [ :issue_labels ] . first ( :label_id => label [ :id ] , :issue_id => issue [ :id ] ) else debug \"Issue label #{name} to issue #{owner}/#{repo} -> #{issue_id} exists\" issue_lbl end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run a block in a DB transaction . Exceptions trigger transaction rollback and are rethrown . [CODESPLIT] def transaction ( & block ) db persister result = nil start_time = Time . now begin db . transaction ( :rollback => :reraise , :isolation => :repeatable , :retry_on => @retry_on_error , :num_retries => 3 ) do result = yield block end total = Time . now . to_ms - start_time . to_ms debug \"Transaction committed (#{total} ms)\" result rescue StandardError => e total = Time . now . to_ms - start_time . to_ms warn \"Transaction failed (#{total} ms)\" raise e ensure GC . start end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Store a commit contained in a hash . First check whether the commit exists . [CODESPLIT] def store_commit ( c , repo , user ) commits = db [ :commits ] commit = commits . first ( :sha => c [ 'sha' ] ) if commit . nil? author = commit_user ( c [ 'author' ] , c [ 'commit' ] [ 'author' ] ) commiter = commit_user ( c [ 'committer' ] , c [ 'commit' ] [ 'committer' ] ) repository = ensure_repo ( user , repo ) if repository . nil? warn \"Could not find repo #{user}/#{repo} for storing commit #{c['sha']}\" end commits . insert ( :sha => c [ 'sha' ] , :author_id => author [ :id ] , :committer_id => commiter [ :id ] , :project_id => if repository . nil? then nil else repository [ :id ] end , :created_at => date ( c [ 'commit' ] [ 'author' ] [ 'date' ] ) ) info \"Added commit #{user}/#{repo} -> #{c['sha']} \" commits . first ( :sha => c [ 'sha' ] ) else debug \"Commit #{user}/#{repo} -> #{c['sha']} exists\" commit end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Dates returned by Github are formatted as : - yyyy - mm - ddThh : mm : ssZ - yyyy / mm / dd hh : mm : ss { + / - } hhmm [CODESPLIT] def date ( arg ) if arg . class != Time time_non_zero ( Time . parse ( arg ) ) else time_non_zero ( arg ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Default logger [CODESPLIT] def loggerr @logger ||= proc do @logger_uniq ||= config ( :logging_uniq ) logger = if config ( :logging_file ) . casecmp ( 'stdout' ) Logger . new ( STDOUT ) elsif config ( :logging_file ) . casecmp ( 'stderr' ) Logger . new ( STDERR ) else Logger . new ( config ( :logging_file ) ) end logger . level = case config ( :logging_level ) . downcase when 'debug' then Logger :: DEBUG when 'info' then Logger :: INFO when 'warn' then Logger :: WARN when 'error' then Logger :: ERROR else Logger :: INFO end logger . formatter = proc do | severity , time , progname , msg | if progname . nil? or progname . empty? progname = @logger_uniq end \"#{severity}, #{time.iso8601}, #{progname} -- #{msg}\\n\" end logger end . call @logger end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Log a message at the given level . [CODESPLIT] def log ( level , msg ) case level when :fatal then loggerr . fatal ( retrieve_caller + msg ) when :error then loggerr . error ( retrieve_caller + msg ) when :warn then loggerr . warn ( retrieve_caller + msg ) when :info then loggerr . info ( retrieve_caller + msg ) when :debug then loggerr . debug ( retrieve_caller + msg ) else loggerr . debug ( retrieve_caller + msg ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A paged request . Used when the result can expand to more than one result pages . [CODESPLIT] def paged_api_request ( url , pages = config ( :mirror_history_pages_back ) , last = nil ) url = ensure_max_per_page ( url ) data = api_request_raw ( url ) return [ ] if data . nil? unless data . meta [ 'link' ] . nil? links = parse_links ( data . meta [ 'link' ] ) last = links [ 'last' ] if last . nil? if pages > 0 pages = pages - 1 if pages == 0 return parse_request_result ( data ) end end if links [ 'next' ] . nil? parse_request_result ( data ) else parse_request_result ( data ) | paged_api_request ( links [ 'next' ] , pages , last ) end else parse_request_result ( data ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check whether the resource identified by the provided url has changed [CODESPLIT] def last_updated ( url , etag ) begin ts = Time . now response = do_request ( url , '' , etag ) info \"Successful etag request. URL: #{url}, Etag: #{etag}, Remaining: #{@remaining}, Total: #{Time.now.to_ms - ts.to_ms} ms\" rescue OpenURI :: HTTPError => e response = e . io if response . status . first != '304' etag_request_error_message ( url , e , etag ) raise e end end return Time . parse ( response . meta [ 'last-modified' ] ) unless response . meta [ 'last-modified' ] . nil? return Time . at ( 86400 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine the number of pages contained in a multi - page API response [CODESPLIT] def num_pages ( url ) url = ensure_max_per_page ( url ) data = api_request_raw ( url ) if data . nil? or data . meta . nil? or data . meta [ 'link' ] . nil? return 1 end links = parse_links ( data . meta [ 'link' ] ) if links . nil? or links [ 'last' ] . nil? return 1 end params = CGI :: parse ( URI :: parse ( links [ 'last' ] ) . query ) params [ 'page' ] [ 0 ] . to_i end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse a Github link header [CODESPLIT] def parse_links ( links ) links . split ( / / ) . reduce ( { } ) do | acc , x | matches = x . strip . match ( / \\\" \\\" / ) acc [ matches [ 2 ] ] = matches [ 1 ] acc end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse the JSON result array [CODESPLIT] def parse_request_result ( result ) if result . nil? [ ] else json = result . read if json . nil? [ ] else r = JSON . parse ( json ) # Add the etag to the response only for individual entities if result . meta [ 'etag' ] and r . class != Array r [ 'etag' ] = result . meta [ 'etag' ] end r end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Do the actual request and return the result object [CODESPLIT] def api_request_raw ( url , media_type = '' ) begin start_time = Time . now contents = do_request ( url , media_type ) total = Time . now . to_ms - start_time . to_ms info \"Successful request. URL: #{url}, Remaining: #{@remaining}, Total: #{total} ms\" contents rescue OpenURI :: HTTPError => e @remaining = e . io . meta [ 'x-ratelimit-remaining' ] . to_i @reset = e . io . meta [ 'x-ratelimit-reset' ] . to_i case e . io . status [ 0 ] . to_i # The following indicate valid Github return codes when 400 , # Bad request 403 , # Forbidden 404 , # Not found 409 , # Conflict -- returned on gets of empty repos 422 then # Unprocessable entity warn request_error_msg ( url , e ) return nil when 401 # Unauthorized warn request_error_msg ( url , e ) warn \"Unauthorised request with token: #{@token}\" raise e when 451 # DMCA takedown warn request_error_msg ( url , e ) warn \"Repo was taken down (DMCA)\" return nil else # Server error or HTTP conditions that Github does not report warn request_error_msg ( url , e ) raise e end rescue StandardError => e warn error_msg ( url , e ) raise e ensure # The exact limit is only enforced upon the first @reset # No idea how many requests are available on this key. Sleep if we have run out if @remaining < @req_limit to_sleep = @reset - Time . now . to_i + 2 warn \"Request limit reached, reset in: #{to_sleep} secs\" t = Thread . new do slept = 0 while true do debug \"Sleeping for #{to_sleep - slept} seconds\" sleep 1 slept += 1 end end sleep ( [ 0 , to_sleep ] . max ) t . exit end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Attach to a specific IP address if the machine has multiple [CODESPLIT] def attach_to ( ip ) TCPSocket . instance_eval do ( class << self ; self ; end ) . instance_eval do alias_method :original_open , :open case RUBY_VERSION when / / , / / define_method ( :open ) do | conn_address , conn_port | original_open ( conn_address , conn_port , ip ) end else define_method ( :open ) do | conn_address , conn_port , local_host , local_port | original_open ( conn_address , conn_port , ip , local_port ) end end end end result = begin yield rescue StandardError => e raise e ensure TCPSocket . instance_eval do ( class << self ; self ; end ) . instance_eval do alias_method :open , :original_open remove_method :original_open end end end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Factory method for retrieving persistence connections . The + settings + argument is a fully parsed YAML document passed on to adapters . The available + adapter + are mongo and noop [CODESPLIT] def connect ( adapter , settings ) driver = ADAPTERS [ adapter . intern ] driver . new ( settings ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try Github user search by email . This is optional info so it may not return any data . If this fails try searching by name http : // developer . github . com / v3 / search / #email - search [CODESPLIT] def retrieve_user_byemail ( email , name ) url = ghurl ( \"legacy/user/email/#{CGI.escape(email)}\" ) byemail = api_request ( url ) if byemail . nil? or byemail . empty? # Only search by name if name param looks like a proper name byname = if not name . nil? and name . split ( / / ) . size > 1 url = ghurl ( \"legacy/user/search/#{CGI.escape(name)}\" ) api_request ( url ) end if byname . nil? or byname [ 'users' ] . nil? or byname [ 'users' ] . empty? nil else user = byname [ 'users' ] . find do | u | u [ 'name' ] == name and not u [ 'login' ] . nil? and not retrieve_user_byusername ( u [ 'login' ] ) . nil? end unless user . nil? # Make extra sure that if we got an email it matches that # of the retrieved user if not email . nil? and user [ 'email' ] == email user else warn \"Could not find user #{email}\" nil end else warn \"Could not find user #{email}\" nil end end else unless byemail [ 'user' ] [ 'login' ] . nil? info \"Added user #{byemail['user']['login']} retrieved by email #{email}\" retrieve_user_byusername ( byemail [ 'user' ] [ 'login' ] ) else u = byemail [ 'user' ] unq = persister . store ( :users , u ) what = user_type ( u [ 'type' ] ) info \"Added user #{what} #{user}\" u end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a single commit from a repo [CODESPLIT] def retrieve_commit ( repo , sha , user ) commit = persister . find ( :commits , { 'sha' => \"#{sha}\" } ) if commit . empty? url = ghurl \"repos/#{user}/#{repo}/commits/#{sha}\" c = api_request ( url ) if c . nil? or c . empty? return end # commit patches are big and not always interesting if config ( :commit_handling ) == 'trim' c [ 'files' ] . each { | file | file . delete ( 'patch' ) } end persister . store ( :commits , c ) info \"Added commit #{user}/#{repo} -> #{sha}\" c else debug \"Commit #{user}/#{repo} -> #{sha} exists\" commit . first end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve commits starting from the provided + sha + [CODESPLIT] def retrieve_commits ( repo , sha , user , pages = - 1 ) url = if sha . nil? ghurl \"repos/#{user}/#{repo}/commits\" else ghurl \"repos/#{user}/#{repo}/commits?sha=#{sha}\" end commits = restricted_page_request ( url , pages ) commits . map do | c | retrieve_commit ( repo , c [ 'sha' ] , user ) end . select { | x | not x . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve organizations the provided user participates into [CODESPLIT] def retrieve_orgs ( user ) url = ghurl \"users/#{user}/orgs\" orgs = paged_api_request ( url ) orgs . map { | o | retrieve_org ( o [ 'login' ] ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve organization members [CODESPLIT] def retrieve_org_members ( org ) stored_org_members = persister . find ( :org_members , { 'org' => org } ) org_members = paged_api_request ( ghurl \"orgs/#{org}/members\" ) org_members . each do | x | x [ 'org' ] = org exists = ! stored_org_members . find { | f | f [ 'org' ] == org && f [ 'login' ] == x [ 'login' ] } . nil? if not exists persister . store ( :org_members , x ) info \"Added org_member #{org} -> #{x['login']}\" else debug \"Org Member #{org} -> #{x['login']} exists\" end end persister . find ( :org_members , { 'org' => org } ) . map { | o | retrieve_org ( o [ 'login' ] ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve all comments for a single commit [CODESPLIT] def retrieve_commit_comments ( owner , repo , sha ) retrieved_comments = paged_api_request ( ghurl \"repos/#{owner}/#{repo}/commits/#{sha}/comments\" ) retrieved_comments . each { | x | if persister . find ( :commit_comments , { 'commit_id' => x [ 'commit_id' ] , 'id' => x [ 'id' ] } ) . empty? persister . store ( :commit_comments , x ) end } persister . find ( :commit_comments , { 'commit_id' => sha } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a single comment [CODESPLIT] def retrieve_commit_comment ( owner , repo , sha , id ) comment = persister . find ( :commit_comments , { 'commit_id' => sha , 'id' => id } ) . first if comment . nil? r = api_request ( ghurl \"repos/#{owner}/#{repo}/comments/#{id}\" ) if r . nil? or r . empty? warn \"Could not find commit_comment #{id}. Deleted?\" return end persister . store ( :commit_comments , r ) info \"Added commit_comment #{r['commit_id']} -> #{r['id']}\" persister . find ( :commit_comments , { 'commit_id' => sha , 'id' => id } ) . first else debug \"Commit comment #{comment['commit_id']} -> #{comment['id']} exists\" comment end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve all watchers for a repository [CODESPLIT] def retrieve_watchers ( user , repo ) repo_bound_items ( user , repo , :watchers , [ \"repos/#{user}/#{repo}/stargazers\" ] , { 'repo' => repo , 'owner' => user } , 'login' , item = nil , refresh = false , order = :desc ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a single watcher for a repository [CODESPLIT] def retrieve_watcher ( user , repo , watcher ) repo_bound_item ( user , repo , watcher , :watchers , [ \"repos/#{user}/#{repo}/stargazers\" ] , { 'repo' => repo , 'owner' => user } , 'login' , order = :desc ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all events for the specified repo . GitHub will only return 90 days of events [CODESPLIT] def get_repo_events ( owner , repo ) url = ghurl ( \"repos/#{owner}/#{repo}/events\" ) r = paged_api_request ( url ) r . each do | e | unless get_event ( e [ 'id' ] ) . empty? debug \"Repository event #{owner}/#{repo} -> #{e['type']}-#{e['id']} already exists\" else persister . store ( :events , e ) info \"Added event for repository #{owner}/#{repo} -> #{e['type']}-#{e['id']}\" end end persister . find ( :events , { 'repo.name' => \"#{owner}/#{repo}\" } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve diff between two branches . If either branch name is not provided the branch name is resolved to the corresponding default branch [CODESPLIT] def retrieve_master_branch_diff ( owner , repo , branch , parent_owner , parent_repo , parent_branch ) branch = retrieve_default_branch ( owner , repo ) if branch . nil? parent_branch = retrieve_default_branch ( parent_owner , parent_repo ) if parent_branch . nil? return nil if branch . nil? or parent_branch . nil? cmp_url = \"https://api.github.com/repos/#{parent_owner}/#{parent_repo}/compare/#{parent_branch}...#{owner}:#{branch}\" api_request ( cmp_url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve the default branch for a repo . If nothing is retrieved master is returned [CODESPLIT] def retrieve_default_branch ( owner , repo , refresh = false ) retrieved = retrieve_repo ( owner , repo , refresh ) return nil if retrieved . nil? master_branch = 'master' if retrieved [ 'default_branch' ] . nil? # The currently stored repo entry has been created before the # default_branch field was added to the schema retrieved = retrieve_repo ( owner , repo , true ) return nil if retrieved . nil? end master_branch = retrieved [ 'default_branch' ] unless retrieved . nil? master_branch end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Specify and parse top - level command line options . [CODESPLIT] def process_options command = self @options = Trollop :: options ( command . args ) do command . prepare_options ( self ) banner <<-END END opt :config , 'config.yaml file location' , :short => 'c' , :default => 'config.yaml' opt :verbose , 'verbose mode' , :short => 'v' opt :addr , 'IP address to use for performing requests' , :short => 'a' , :type => String opt :token , 'GitHub OAuth token' , :type => String , :short => 't' opt :req_limit , 'Number or requests to leave on any provided account (in reqs/hour)' , :type => Integer , :short => 'l' opt :uniq , 'Unique name for this command. Will appear in logs.' , :type => String , :short => 'u' end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Examine the validity of the provided options in the context of the executed command . Subclasses can also call super to also invoke the checks provided by this class . [CODESPLIT] def validate if options [ :config ] . nil? unless ( File . exist? ( \"config.yaml\" ) ) Trollop :: die \"No config file in default location (#{Dir.pwd}). You\n                        need to specify the #{:config} parameter. Read the\n                        documentation on how to create a config.yaml file.\" end else Trollop :: die \"Cannot find file #{options[:config]}\" unless File . exist? ( options [ :config ] ) end unless @options [ :user ] . nil? if not Process . uid == 0 Trollop :: die \"Option --user (-u) can only be specified by root\" end begin Etc . getpwnam ( @options [ :user ] ) rescue ArgumentError Trollop :: die \"No such user: #{@options[:user]}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Specify a handler to incoming messages from a connection to a queue . [CODESPLIT] def queue_client ( queue , key = queue , ack = :after , block ) stopped = false while not stopped begin conn = Bunny . new ( :host => config ( :amqp_host ) , :port => config ( :amqp_port ) , :username => config ( :amqp_username ) , :password => config ( :amqp_password ) ) conn . start ch = conn . create_channel debug \"Queue setting prefetch to #{config(:amqp_prefetch)}\" ch . prefetch ( config ( :amqp_prefetch ) ) debug \"Queue connection to #{config(:amqp_host)} succeeded\" x = ch . topic ( config ( :amqp_exchange ) , :durable => true , :auto_delete => false ) q = ch . queue ( queue , :durable => true ) q . bind ( x , :routing_key => key ) q . subscribe ( :block => true , :manual_ack => true ) do | delivery_info , properties , msg | if ack == :before ch . acknowledge ( delivery_info . delivery_tag ) end begin block . call ( msg ) ensure if ack != :before ch . acknowledge ( delivery_info . delivery_tag ) end end end rescue Bunny :: TCPConnectionFailed => e warn \"Connection to #{config(:amqp_host)} failed. Retrying in 1 sec\" sleep ( 1 ) rescue Bunny :: PossibleAuthenticationFailureError => e warn \"Could not authenticate as #{conn.username}\" rescue Bunny :: NotFound , Bunny :: AccessRefused , Bunny :: PreconditionFailed => e warn \"Channel error: #{e}. Retrying in 1 sec\" sleep ( 1 ) rescue Interrupt => _ stopped = true rescue StandardError => e raise e end end ch . close unless ch . nil? conn . close unless conn . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read the value for a key whose format is foo . bar . baz from a hierarchical map where a dot represents one level deep in the hierarchy . [CODESPLIT] def read_value ( from , key ) return from if key . nil? or key == \"\" key . split ( / \\. / ) . reduce ( { } ) do | acc , x | unless acc . nil? if acc . empty? # Initial run acc = from [ x ] else if acc . has_key? ( x ) acc = acc [ x ] else # Some intermediate key does not exist return nil end end else # Some intermediate key returned a null value # This indicates a malformed entry return nil end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Overwrite an existing + key + whose format is foo . bar ( where a dot represents one level deep in the hierarchy ) in hash + to + with + value + . If the key does not exist it will be added at the appropriate depth level [CODESPLIT] def write_value ( to , key , value ) return to if key . nil? or key == \"\" prev = nil key . split ( / \\. / ) . reverse . each { | x | a = Hash . new a [ x ] = if prev . nil? then value else prev end prev = a a } to . merge_recursive ( prev ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a location string it returns a hash like the following : [CODESPLIT] def geolocate ( location : nil , wait : config ( :geolocation_wait ) . to_i , from_cache : true ) return EMPTY_LOCATION if location . nil? or location == '' location = location_filter ( location ) geo = [ ] if from_cache geo = persister . find ( :geo_cache , { 'key' => location } ) end if geo . empty? if config ( :geolocation_service ) == 'gmaps' self . class . send :include , GHTorrent :: Geolocator :: GMaps elsif config ( :geolocation_service ) == 'bing' self . class . send :include , GHTorrent :: Geolocator :: Bing else self . class . send :include , GHTorrent :: Geolocator :: OSM end begin ts = Time . now url = format_url ( location ) req = open ( url ) p = JSON . parse ( req . read ) geo = parse_geolocation_result ( location , p ) info \"Successful geolocation request. Location: #{location}\" rescue StandardError => e warn \"Failed geolocation request. Location: #{location}\" geo = EMPTY_LOCATION geo [ :key ] = location ensure in_db_geo = persister . find ( :geo_cache , { 'key' => location } ) . first if in_db_geo . nil? begin geo [ :updated_at ] = Time . now persister . store ( :geo_cache , geo ) rescue StandardError => e warn \"Could not save location #{location} -> #{geo}: #{e.message}\" end end info \"Added location key '#{location}' -> #{geo[:status]}\" taken = Time . now . to_f - ts . to_f to_sleep = wait - taken sleep ( to_sleep ) if to_sleep > 0 end else geo = geo [ 0 ] debug \"Location with key '#{location}' exists\" end geo end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Standard filtering on all locations used by GHTorrent [CODESPLIT] def location_filter ( location ) return nil if location . nil? location . strip . downcase . tr ( '#\"<>[]' , '' ) . gsub ( / \\/ / , '' ) . gsub ( / / , ' ' ) . gsub ( / / , '\\1' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if we met all the topics requirements . It will fail if we didn t send a message to a registered required topic etc . [CODESPLIT] def validate_usage! registered_topics = self . class . topics . map do | name , topic | topic . to_h . merge! ( usage_count : messages_buffer [ name ] &. count || 0 ) end used_topics = messages_buffer . map do | name , usage | topic = self . class . topics [ name ] || Responders :: Topic . new ( name , registered : false ) topic . to_h . merge! ( usage_count : usage . count ) end result = Karafka :: Schemas :: ResponderUsage . call ( registered_topics : registered_topics , used_topics : used_topics ) return if result . success? raise Karafka :: Errors :: InvalidResponderUsageError , result . errors end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if we met all the options requirements before sending them to the producer . [CODESPLIT] def validate_options! return true unless self . class . options_schema messages_buffer . each_value do | messages_set | messages_set . each do | message_data | result = self . class . options_schema . call ( message_data . last ) next if result . success? raise Karafka :: Errors :: InvalidResponderMessageOptionsError , result . errors end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Takes all the messages from the buffer and delivers them one by one [CODESPLIT] def deliver! messages_buffer . each_value do | data_elements | data_elements . each do | data , options | # We map this topic name, so it will match namespaced/etc topic in Kafka # @note By default will not change topic (if default mapper used) mapped_topic = Karafka :: App . config . topic_mapper . outgoing ( options [ :topic ] ) external_options = options . merge ( topic : mapped_topic ) producer ( options ) . call ( data , external_options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method allow us to respond to a single topic with a given data . It can be used as many times as we need . Especially when we have 1 : n flow [CODESPLIT] def respond_to ( topic , data , options = { } ) # We normalize the format to string, as WaterDrop and Ruby-Kafka support only # string topics topic = topic . to_s messages_buffer [ topic ] ||= [ ] messages_buffer [ topic ] << [ self . class . topics [ topic ] . serializer . call ( data ) , options . merge ( topic : topic ) ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Informs monitoring about trapped signal [CODESPLIT] def notice_signal ( signal ) Thread . new do Karafka . monitor . instrument ( 'process.notice_signal' , caller : self , signal : signal ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Looks up ids in a list of embedding tensors . [CODESPLIT] def embedding_lookup ( params , ids , partition_strategy : \"mod\" , name : nil , validate_indices : true , max_norm : nil ) _embedding_lookup_and_transform ( params , ids , partition_strategy : partition_strategy , name : name , max_norm : max_norm , transform_fn : nil ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helper function for embedding_lookup and _compute_sampled_logits . [CODESPLIT] def _embedding_lookup_and_transform ( params , ids , partition_strategy : \"mod\" , name : nil , max_norm : nil , transform_fn : nil ) raise TensorStream :: ValueError , \"Need at least one param\" if params . nil? params = [ params ] unless params . is_a? ( Array ) TensorStream . name_scope ( name , \"embedding_lookup\" , values : params + [ ids ] ) do | name | np = params . size ids = TensorStream . convert_to_tensor ( ids , name : \"ids\" ) if ( np == 1 ) && ( transform_fn . nil? || ( ids . shape . size == 1 ) ) result = nil TensorStream . colocate_with ( params [ 0 ] ) do result = _clip ( TensorStream . gather ( params [ 0 ] , ids , name : name ) , ids , max_norm ) result = transform_fn . call ( result ) if transform_fn end return TensorStream . identity ( result ) else flat_ids = TensorStream . reshape ( ids , [ - 1 ] ) original_indices = TensorStream . range ( TensorStream . size ( flat_ids ) ) p_assignments = nil new_ids = nil if partition_strategy == \"mod\" p_assignments = flat_ids % np new_ids = floor_div ( flat_ids , np ) elsif partition_strategy == \"div\" raise \"not yet supported!\" else raise TensorStream :: ValueError , \"Unrecognized partition strategy: \" + partition_strategy end p_assignments = TensorStream . cast ( p_assignments , :int32 ) gather_ids = TensorStream . dynamic_partition ( new_ids , p_assignments , np ) pindices = TensorStream . dynamic_partition ( original_indices , p_assignments , np ) partitioned_result = [ ] ( 0 ... np ) . each do | p | pids = gather_ids [ p ] result = nil TensorStream . colocate_with ( params [ p ] ) do result = TensorStream . gather ( params [ p ] , pids ) if transform_fn # If transform_fn is provided, the clip_by_norm precedes # the transform and hence must be co-located. See below # for the counterpart if transform_fn is not proveded. result = transform_fn . call ( _clip ( result , pids , max_norm ) ) end end partitioned_result << result end ret = TensorStream . dynamic_stitch ( pindices , partitioned_result , name : name ) if transform_fn . nil? element_shape_s = params [ 0 ] . shape [ 1 .. - 1 ] params [ 1 .. - 1 ] . each { | p | element_shape_s = element_shape_s . merge_with ( p . shape [ 1 .. - 1 ] ) } else element_shape_s = ret . shape [ 1 .. - 1 ] end # Compute the dynamic element shape. element_shape_d = if element_shape_s . fully_defined? element_shape_s elsif transform_fn . nil? # It's important that we compute params[0].shape on the right device # to avoid data motion. TensorStream . colocate_with ( params [ 0 ] ) do params_shape = TensorStream . shape ( params [ 0 ] ) params_shape [ 1 .. - 1 ] end else TensorStream . shape ( ret ) [ 1 .. - 1 ] end ret = TensorStream . reshape ( ret , TensorStream . concat ( [ TensorStream . shape ( ids ) , element_shape_d ] , 0 ) ) ret = _clip ( ret , ids , max_norm ) unless transform_fn ret end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parsers a protobuf file and spits out a ruby hash [CODESPLIT] def load ( pbfile ) f = File . new ( pbfile , \"r\" ) lines = [ ] while ! f . eof? && ( str = f . readline . strip ) lines << str end evaluate_lines ( lines ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assert the condition x == y holds element - wise . [CODESPLIT] def assert_equal ( x , y , data : nil , summarize : nil , message : nil , name : nil ) _op ( :assert_equal , x , y , data : data , summarize : summarize , message : message , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Constructs symbolic derivatives of ys of input w . r . t . x in wrt_xs . [CODESPLIT] def gradients ( tensor_ys , wrt_xs , name : \"gradients\" , stop_gradients : nil ) tensor_ys = tensor_ys . op gs = wrt_xs . map ( :op ) . collect { | x | stops = stop_gradients ? stop_gradients . map ( :name ) . join ( \"_\" ) : \"\" gradient_program_name = \"grad_#{tensor_ys.name}_#{x.name}_#{stops}\" . to_sym tensor_graph = tensor_ys . graph tensor_program = if tensor_graph . node_added? ( gradient_program_name ) tensor_graph . get_node ( gradient_program_name ) else tensor_graph . name_scope ( \"gradient_wrt_#{x.name}\" ) do derivative_ops = TensorStream :: MathGradients . derivative ( tensor_ys , x , graph : tensor_graph , stop_gradients : stop_gradients ) tensor_graph . add_node! ( gradient_program_name , derivative_ops ) end end tensor_program } gs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Outputs random values from a normal distribution . [CODESPLIT] def random_normal ( shape , dtype : :float32 , mean : 0.0 , stddev : 1.0 , seed : nil , name : nil ) options = { dtype : dtype , mean : mean , stddev : stddev , seed : seed , name : name } _op ( :random_standard_normal , shape , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Construct an identity matrix [CODESPLIT] def eye ( num_rows , num_columns : nil , dtype : :float32 , name : nil ) _op ( :eye , num_rows , num_columns || num_rows , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The Glorot uniform initializer also called Xavier uniform initializer . [CODESPLIT] def glorot_uniform_initializer ( seed : nil , dtype : nil ) TensorStream :: Initializer . new ( -> { _op ( :glorot_uniform , seed : seed , data_type : dtype ) } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initializer that generates tensors with a uniform distribution . [CODESPLIT] def random_uniform_initializer ( minval : 0 , maxval : 1 , seed : nil , dtype : nil ) TensorStream :: Initializer . new ( -> { _op ( :random_uniform , minval : 0 , maxval : 1 , seed : seed , data_type : dtype ) } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extracts a slice from a tensor . [CODESPLIT] def slice ( input , start , size , name : nil ) _op ( :slice , input , start , size : size , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a tensor with all elements set to 1 . [CODESPLIT] def ones ( shape , dtype : :float32 , name : nil ) _op ( :ones , shape , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of x AND y element - wise . [CODESPLIT] def logical_and ( input_a , input_b , name : nil ) check_data_types ( input_a , input_b ) _op ( :logical_and , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the mean of elements across dimensions of a tensor . [CODESPLIT] def reduce_mean ( input_tensor , axis = nil , keepdims : false , name : nil ) reduce ( :mean , input_tensor , axis , keepdims : keepdims , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Concatenates tensors along one dimension . [CODESPLIT] def concat ( values , axis , name : \"concat\" ) if values . is_a? ( Array ) _op ( :concat , axis , values , name : name ) else _op ( :concat , axis , values , name : name ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Partitions data into num_partitions tensors using indices from partitions [CODESPLIT] def dynamic_partition ( data , partitions , num_partitions , name : nil ) result = _op ( :dynamic_partition , data , partitions , num_partitions : num_partitions , name : nil ) num_partitions . times . map do | index | result [ index ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return true_fn () if the predicate pred is true else false_fn () . [CODESPLIT] def cond ( pred , true_fn , false_fn , name : nil ) _op ( :case , [ pred ] , false_fn , true_fn , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the elements either from x or y depending on the condition . [CODESPLIT] def where ( condition , true_t = nil , false_t = nil , name : nil ) _op ( :where , condition , true_t , false_t , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes asin of input element - wise [CODESPLIT] def asin ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :asin , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes acos of input element - wise [CODESPLIT] def acos ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :acos , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes atan of input element - wise [CODESPLIT] def atan ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :atan , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns element - wise integer divistion . [CODESPLIT] def floor_div ( input_a , input_b , name : nil ) check_data_types ( input_a , input_b ) _op ( :floor_div , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Casts a tensor to a new type if needed [CODESPLIT] def cast ( input , dtype , name : nil ) input = convert_to_tensor ( input ) return input if input . data_type == dtype _op ( :cast , input , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a list of tensors . [CODESPLIT] def print ( input , data , message : nil , name : nil ) _op ( :print , input , data , message : message , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x ! = y ) element - wise . This ops supports broadcasting [CODESPLIT] def not_equal ( input_a , input_b , name : nil ) check_data_types ( input_a , input_b ) _op ( :not_equal , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "reates a tensor with all elements set to zero . Given a single tensor ( tensor ) this operation returns a tensor of the same type and shape as tensor with all elements set to zero . Optionally you can use dtype to specify a new type for the returned tensor . [CODESPLIT] def zeros_like ( tensor , dtype : nil , name : nil ) _op ( :zeros_like , tensor , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a tensor with all elements set to 1 . Given a single tensor ( tensor ) this operation returns a tensor of the same type and shape as tensor with all elements set to 1 . Optionally you can specify a new type ( dtype ) for the returned tensor . [CODESPLIT] def ones_like ( tensor , dtype : nil , name : nil ) _op ( :ones_like , tensor , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns x * y element - wise . This operation supports broadcasting [CODESPLIT] def multiply ( input_a , input_b , name : nil ) check_data_types ( input_a , input_b ) _op ( :mul , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes sec of input element - wise . [CODESPLIT] def sec ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :sec , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes sqrt of input element - wise . [CODESPLIT] def sqrt ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :sqrt , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes natural logarithm of x element - wise . [CODESPLIT] def log ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :log , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes natural logarithm of ( 1 + x ) element - wise . [CODESPLIT] def log1p ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :log1p , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes exponential of x element - wise . [CODESPLIT] def exp ( input , name : nil ) check_allowed_types ( input , FLOATING_POINT_TYPES ) _op ( :exp , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pads a tensor . This operation pads a tensor according to the paddings you specify . [CODESPLIT] def pad ( tensor , paddings , mode : \"CONSTANT\" , name : nil ) _op ( :pad , tensor , paddings , mode : mode , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks a tensor for NaN and Inf values . When run reports an InvalidArgument error if tensor has any values that are not a number ( NaN ) or infinity ( Inf ) . Otherwise passes tensor as - is . [CODESPLIT] def check_numerics ( tensor , message , name : nil ) _op ( :check_numerics , tensor , message : message , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gather slices from params and axis according to indices . [CODESPLIT] def gather ( params , indices , validate_indices : nil , name : nil , axis : 0 ) _op ( :gather , params , indices , validate_indices : validate_indices , name : name , axis : axis ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stacks a list of rank - R tensors into one rank - ( R + 1 ) tensor . [CODESPLIT] def stack ( values , axis : 0 , name : \"stack\" ) _op ( :stack , values , axis : axis , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Unpacks the given dimension of a rank - R tensor into rank - ( R - 1 ) tensors . [CODESPLIT] def unstack ( value , num : nil , axis : 0 , name : \"unstack\" ) res = _op ( :unstack , value , num : num , axis : axis , name : name ) num_vars = if value . shape . known? new_shape = value . shape . shape . dup rank = new_shape . size - 1 axis = rank + axis if axis < 0 rotated_shape = Array . new ( axis + 1 ) { new_shape . shift } new_shape = rotated_shape . rotate! ( - 1 ) + new_shape new_shape [ 0 ] else raise TensorStream :: ValueError , \"num is unspecified and cannot be inferred.\" if num . nil? num end return res [ 0 ] if num_vars == 1 Array . new ( num_vars ) do | i | index ( res , i , name : \"unstack/index:#{i}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Same as stack [CODESPLIT] def pack ( values , axis : 0 , name : \"pack\" ) _op ( :stack , values , axis : axis , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Same as unstack [CODESPLIT] def unpack ( value , num : nil , axis : 0 , name : \"unpack\" ) unstack ( value , num : num , axis : axis , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the difference between two lists of numbers or strings . Given a list x and a list y this operation returns a list out that represents all values that are in x but not in y . The returned list out is sorted in the same order that the numbers appear in x ( duplicates are preserved ) . This operation also returns a list idx that represents the position of each out element in x . In other words : [CODESPLIT] def setdiff1d ( x , y , index_dtype : :int32 , name : nil ) result = _op ( :setdiff1d , x , y , index_dtype : index_dtype , name : name ) [ result [ 0 ] , result [ 1 ] ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a case operation . [CODESPLIT] def case ( args = { } ) args = args . dup default = args . delete ( :default ) exclusive = args . delete ( :exclusive ) strict = args . delete ( :strict ) name = args . delete ( :name ) predicates = [ ] functions = [ ] args . each do | k , v | raise \"Invalid argment or option #{k}\" unless k . is_a? ( Tensor ) predicates << k functions << ( v . is_a? ( Proc ) ? v . call : v ) end _op ( :case , predicates , default , functions , exclusive : exclusive , strict : strict , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "same as op but with a marker that it was internal generated [CODESPLIT] def i_op ( code , * args ) options = if args . last . is_a? ( Hash ) args . pop else { } end args << options . merge ( internal : true ) Graph . get_default_graph . add_op! ( code . to_sym , args ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "explicit broadcasting helper [CODESPLIT] def broadcast_dimensions ( input , dims = [ ] ) return input if dims . empty? d = dims . shift if input . is_a? ( Array ) && ( get_rank ( input ) - 1 ) == dims . size row_to_dup = input . collect { | item | broadcast_dimensions ( item , dims . dup ) } row_to_dup + Array . new ( d ) { row_to_dup } . flatten ( 1 ) elsif input . is_a? ( Array ) Array . new ( d ) { broadcast_dimensions ( input , dims . dup ) } else Array . new ( d + 1 ) { input } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "handle 2 tensor math operations [CODESPLIT] def vector_op ( vector , vector2 , switch = false , safe = true , & block ) if get_rank ( vector ) < get_rank ( vector2 ) # upgrade rank of A duplicated = Array . new ( vector2 . size ) { vector } return vector_op ( duplicated , vector2 , switch , block ) end return yield ( vector , vector2 ) unless vector . is_a? ( Array ) vector . each_with_index . collect { | input , index | next vector_op ( input , vector2 , switch , block ) if input . is_a? ( Array ) && get_rank ( vector ) > get_rank ( vector2 ) if safe && vector2 . is_a? ( Array ) next nil if vector2 . size != 1 && index >= vector2 . size end z = if vector2 . is_a? ( Array ) if index < vector2 . size vector2 [ index ] else raise \"incompatible tensor shapes used during op\" if vector2 . size != 1 vector2 [ 0 ] end else vector2 end if input . is_a? ( Array ) vector_op ( input , z , switch , block ) else switch ? yield ( z , input ) : yield ( input , z ) end } . compact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "general case transposition with flat arrays [CODESPLIT] def transpose_with_perm ( arr , new_arr , shape , new_shape , perm ) arr_size = shape . reduce ( :* ) divisors = shape . dup . drop ( 1 ) . reverse . inject ( [ 1 ] ) { | a , s | a << s * a . last } . reverse multipliers = new_shape . dup . drop ( 1 ) . reverse . inject ( [ 1 ] ) { | a , s | a << s * a . last } . reverse arr_size . times do | p | ptr = p index = [ ] divisors . each_with_object ( index ) do | div , a | a << ( ptr / div . to_f ) . floor ptr = ptr % div end # remap based on perm remaped = perm . map { | x | index [ x ] } ptr2 = 0 multipliers . each_with_index do | m , idx | ptr2 += remaped [ idx ] * m end new_arr [ ptr2 ] = arr [ p ] end [ new_arr , new_shape ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns x + y element - wise . [CODESPLIT] def add ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :add , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the index with the largest value across axes of a tensor . [CODESPLIT] def argmax ( input_a , axis = nil , name : nil , dimension : nil , output_type : :int32 ) check_allowed_types ( input_a , TensorStream :: Ops :: NUMERIC_TYPES ) check_allowed_types ( axis , TensorStream :: Ops :: INTEGER_TYPES ) _op ( :argmax , input_a , axis , name : name , dimension : dimension , output_type : output_type ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns element - wise smallest integer in not less than x [CODESPLIT] def ceil ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :ceil , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes cos of input element - wise . [CODESPLIT] def cos ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :cos , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns x / y element - wise . [CODESPLIT] def div ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :div , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x == y ) element - wise . [CODESPLIT] def equal ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :equal , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns element - wise largest integer not greater than x . [CODESPLIT] def floor ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :floor , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns element - wise integer divistion . [CODESPLIT] def floor_div ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :floor_div , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x > y ) element - wise . [CODESPLIT] def greater ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :greater , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x > = y ) element - wise . [CODESPLIT] def greater_equal ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :greater_equal , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x < y ) element - wise . [CODESPLIT] def less ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :less , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x < = y ) element - wise . [CODESPLIT] def less_equal ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :less_equal , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Multiplies matrix a by matrix b producing a * b . The inputs must following any transpositions be tensors of rank 2 . [CODESPLIT] def mat_mul ( input_a , input_b , transpose_a : false , transpose_b : false , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :mat_mul , input_a , input_b , transpose_a : transpose_a , transpose_b : transpose_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the max of x and y ( i . e . x > y ? x : y ) element - wise . [CODESPLIT] def max ( input_a , input_b , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: NUMERIC_TYPES ) check_allowed_types ( input_b , TensorStream :: Ops :: NUMERIC_TYPES ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :max , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns element - wise remainder of division . [CODESPLIT] def mod ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :mod , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns x * y element - wise . [CODESPLIT] def mul ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :mul , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the truth value of ( x ! = y ) element - wise . [CODESPLIT] def not_equal ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :not_equal , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a tensor with all elements set to 1 . Given a single tensor ( tensor ) this operation returns a tensor of the same type and shape as tensor with all elements set to 1 . Optionally you can specify a new type ( dtype ) for the returned tensor . [CODESPLIT] def ones_like ( input , dtype : nil , name : nil ) _op ( :ones_like , input , data_type : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the power of one value to another X^Y element wise [CODESPLIT] def pow ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :pow , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the product of elements across dimensions of a tensor . Reduces input_tensor along the dimensions given in axis . Unless keepdims is true the rank of the tensor is reduced by 1 for each entry in axis . If keepdims is true the reduced dimensions are retained with length 1 . If axis has no entries all dimensions are reduced and a tensor with a single element is returned . [CODESPLIT] def prod ( input_a , axis = nil , name : nil , keepdims : false ) check_allowed_types ( axis , TensorStream :: Ops :: INTEGER_TYPES ) input_a = TensorStream . convert_to_tensor ( input_a ) return input_a if input_a . shape . scalar? axis = cast_axis ( input_a , axis ) _op ( :prod , input_a , axis , name : name , keepdims : keepdims ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Outputs random values from a uniform distribution . [CODESPLIT] def random_uniform ( shape , name : nil , dtype : :float32 , minval : 0 , maxval : 1 , seed : nil ) _op ( :random_uniform , shape , name : name , dtype : dtype , minval : minval , maxval : maxval , seed : seed ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a sequence of numbers . Creates a sequence of numbers that begins at start and extends by increments of delta up to but not including limit . [CODESPLIT] def range ( start = 0 , limit = 0 , delta = 1 , name : \"range\" , dtype : nil , output_type : :int32 ) _op ( :range , start , limit , delta , name : name , dtype : dtype , output_type : output_type ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the rank of a tensor [CODESPLIT] def rank ( input , name : nil ) input = convert_to_tensor ( input ) return cons ( input . shape . ndims ) if input . shape . known? _op ( :rank , input , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rounds the values of a tensor to the nearest integer element - wise [CODESPLIT] def round ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :round , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes reciprocal of square root of x element - wise . [CODESPLIT] def rsqrt ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :rsqrt , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This operation returns a 1 - D integer tensor representing the shape of input [CODESPLIT] def shape ( input , name : nil , out_type : :int32 ) return constant ( shape_eval ( input , out_type ) , dtype : out_type , name : \"Shape/#{name}\" ) if input . is_a? ( Array ) && ! input [ 0 ] . is_a? ( Tensor ) return constant ( input . shape . shape , dtype : out_type , name : \"Shape/#{input.name}_c\" ) if shape_full_specified ( input ) _op ( :shape , input , name : name , out_type : out_type ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes sigmoid of x element - wise . [CODESPLIT] def sigmoid ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :sigmoid , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes sin of input element - wise . [CODESPLIT] def sin ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :sin , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the size of a tensor . Returns a 0 - D Tensor representing the number of elements in input of type out_type . Defaults to : int32 . [CODESPLIT] def size ( input , name : nil , out_type : :int32 ) _op ( :size , input , name : name , out_type : out_type ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extracts a strided slice of a tensor this op extracts a slice of size ( end - begin ) / stride from the given input_ tensor . Starting at the location specified by begin the slice continues by adding stride to the index until all dimensions are not less than end . Note that a stride can be negative which causes a reverse slice . [CODESPLIT] def strided_slice ( input , _begin , _end , strides = nil , name : nil ) _op ( :strided_slice , input , _begin , _end , strides , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns x - y element - wise . [CODESPLIT] def sub ( input_a , input_b , name : nil ) input_a , input_b = apply_data_type_coercion ( input_a , input_b ) _op ( :sub , input_a , input_b , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes the sum of elements across dimensions of a tensor . Reduces input_tensor along the dimensions given in axis . Unless keepdims is true the rank of the tensor is reduced by 1 for each entry in axis . If keepdims is true the reduced dimensions are retained with length 1 . If axis has no entries all dimensions are reduced and a tensor with a single element is returned . [CODESPLIT] def sum ( input_a , axis_p = nil , axis : nil , name : nil , keepdims : false ) check_allowed_types ( axis_p , TensorStream :: Ops :: INTEGER_TYPES ) input_a = TensorStream . convert_to_tensor ( input_a ) return input_a if input_a . shape . scalar? axis_p = axis_p || axis axis_p = cast_axis ( input_a , axis_p ) _op ( :sum , input_a , axis_p , name : name , keepdims : keepdims ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes tan of input element - wise . [CODESPLIT] def tan ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :tan , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes tanh of input element - wise . [CODESPLIT] def tanh ( input_a , name : nil ) check_allowed_types ( input_a , TensorStream :: Ops :: FLOATING_POINT_TYPES ) _op ( :tanh , input_a , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds values and indices of the k largest entries for the last dimension . [CODESPLIT] def top_k ( input , k = 1 , sorted : true , name : nil ) result = _op ( :top_k , input , k , sorted : sorted , name : name ) [ result [ 0 ] , result [ 1 ] ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a tensor with all elements set to zero [CODESPLIT] def zeros ( shape , dtype : :float32 , name : nil ) _op ( :zeros , shape , dtype : dtype , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Utility class to convert variables to constants for production deployment [CODESPLIT] def convert ( session , checkpoint_folder , output_file ) model_file = File . join ( checkpoint_folder , \"model.yaml\" ) TensorStream . graph . as_default do | current_graph | YamlLoader . new . load_from_string ( File . read ( model_file ) ) saver = TensorStream :: Train :: Saver . new saver . restore ( session , checkpoint_folder ) # collect all assign ops and remove them from the graph remove_nodes = Set . new ( current_graph . nodes . values . select { | op | op . is_a? ( TensorStream :: Operation ) && op . operation == :assign } . map { | op | op . consumers . to_a } . flatten . uniq ) output_buffer = TensorStream :: Yaml . new . get_string ( current_graph ) { | graph , node_key | node = graph . get_tensor_by_name ( node_key ) case node . operation when :variable_v2 value = node . container options = { value : value , data_type : node . data_type , shape : shape_eval ( value ) , } const_op = TensorStream :: Operation . new ( current_graph , inputs : [ ] , options : options ) const_op . name = node . name const_op . operation = :const const_op . data_type = node . data_type const_op . shape = TensorShape . new ( shape_eval ( value ) ) const_op when :assign nil else remove_nodes . include? ( node . name ) ? nil : node end } File . write ( output_file , output_buffer ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a context manager that specifies the default device to use . [CODESPLIT] def device ( device_name ) Thread . current [ \"ts_graph_#{object_id}\" ] ||= { } Thread . current [ \"ts_graph_#{object_id}\" ] [ :default_device ] ||= [ ] Thread . current [ \"ts_graph_#{object_id}\" ] [ :default_device ] << device_name begin yield ensure Thread . current [ \"ts_graph_#{object_id}\" ] [ :default_device ] . pop end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Loads a model Yaml file and builds the model from it [CODESPLIT] def load_from_string ( buffer ) serialized_ops = YAML . safe_load ( buffer , [ Symbol ] , [ ] , true ) serialized_ops . each do | op_def | inputs = op_def [ :inputs ] . map { | i | @graph . get_tensor_by_name ( i ) } options = { } new_var = nil if op_def . dig ( :attrs , :container ) new_var = Variable . new ( op_def . dig ( :attrs , :data_type ) ) var_shape = op_def . dig ( :attrs , :container , :shape ) var_options = op_def . dig ( :attrs , :container , :options ) var_options [ :name ] = op_def [ :name ] new_var . prepare ( var_shape . size , var_shape , TensorStream . get_variable_scope , var_options ) options [ :container ] = new_var @graph . add_variable ( new_var , var_options ) end new_op = Operation . new ( @graph , inputs : inputs , options : op_def [ :attrs ] . merge ( options ) ) new_op . operation = op_def [ :op ] . to_sym new_op . name = op_def [ :name ] new_op . shape = TensorShape . new ( TensorStream :: InferShape . infer_shape ( new_op ) ) new_op . rank = new_op . shape . rank new_op . data_type = new_op . set_data_type ( op_def . dig ( :attrs , :data_type ) ) new_op . is_const = new_op . infer_const new_op . given_name = new_op . name new_var . op = new_op if new_var @graph . add_node ( new_op ) end @graph end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List available evaluators + devices in the current local environment Returns : - An array containing the names of those devices [CODESPLIT] def list_local_devices local_name = \"job:localhost\" TensorStream :: Evaluator . evaluators . collect { | k , v | v [ :class ] . query_supported_devices . collect do | device_str | [ local_name , \"ts:#{k}:#{device_str.name}\" ] . join ( \"/\" ) end } . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a variable A variable maintains state across sessions [CODESPLIT] def variable ( value , name : nil , initializer : nil , graph : nil , dtype : nil , trainable : true ) op = Graph . get_default_graph . add_op ( :assign , nil , value ) common_options = { initializer : initializer || op , name : name , graph : graph , dtype : dtype , trainable : trainable , } tensor = if value . is_a? ( String ) i_var ( dtype || :string , 0 , [ ] , get_variable_scope , common_options ) elsif value . is_a? ( Integer ) i_var ( dtype || :int32 , 0 , [ ] , get_variable_scope , common_options ) elsif value . is_a? ( Float ) i_var ( dtype || :float32 , 0 , [ ] , get_variable_scope , common_options ) else i_var ( dtype || :float32 , 0 , nil , get_variable_scope , common_options ) end op . set_input ( 0 , tensor . op ) Graph . get_default_graph . add_node ( op ) tensor end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Defines a variable context manager [CODESPLIT] def variable_scope ( scope = nil , default_name = nil , reuse : nil , initializer : nil ) Thread . current [ :tensor_stream_variable_scope ] ||= [ VariableScope . new ] # uniquenifier if scope . nil? && default_name same_names = get_variable_scope . used_names . select { | s | s . start_with? ( default_name ) } new_name = default_name index = 1 while same_names . include? ( new_name ) new_name = \"#{default_name}_#{index}\" index += 1 end scope = new_name end variable_scope = VariableScope . new ( name : scope , reuse : reuse , initializer : initializer ) get_variable_scope . register_name ( scope || \"\" ) Thread . current [ :tensor_stream_variable_scope ] << variable_scope scope_name = __v_scope_name if block_given? begin TensorStream . get_default_graph . name_scope ( scope ) do yield ( scope_name ) end ensure Thread . current [ :tensor_stream_variable_scope ] . pop end else variable_scope end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a session context where operations can be executed [CODESPLIT] def session ( evaluator = nil , thread_pool_class : Concurrent :: ImmediateExecutor , log_device_placement : false , profile_enabled : false ) session = TensorStream :: Session . new ( evaluator , thread_pool_class : thread_pool_class , log_device_placement : log_device_placement , profile_enabled : profile_enabled ) yield session if block_given? session end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inserts a placeholder for a tensor that will be always fed . [CODESPLIT] def placeholder ( dtype , shape : nil , name : nil ) TensorStream :: Placeholder . new ( dtype , nil , shape , name : name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check to make sure passed array is dense [CODESPLIT] def check_if_dense ( value , expected_shape = nil ) return unless value . is_a? ( Array ) return if value . empty? expected_shape ||= shape_eval ( value ) s = expected_shape . shift raise TensorStream :: ValueError , \"Argument must be a dense tensor: #{value}, expected size #{s} got #{value.size}\" if value . size != s return if expected_shape . empty? value . each do | item | check_if_dense ( item , expected_shape . dup ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Auto cast ruby constant data types to the same tensor types of other operands [CODESPLIT] def apply_data_type_coercion ( * args ) coerced_type = check_data_types ( args ) args . map { | a | a . is_a? ( Tensor ) ? a : convert_to_tensor ( a , dtype : coerced_type ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "database connection [CODESPLIT] def connection @connection ||= begin url = options [ :url ] || ENV [ \"PGSLICE_URL\" ] abort \"Set PGSLICE_URL or use the --url option\" unless url uri = URI . parse ( url ) params = CGI . parse ( uri . query . to_s ) # remove schema @schema = Array ( params . delete ( \"schema\" ) || \"public\" ) [ 0 ] uri . query = URI . encode_www_form ( params ) ENV [ \"PGCONNECT_TIMEOUT\" ] ||= \"1\" PG :: Connection . new ( uri . to_s ) end rescue PG :: ConnectionBad => e abort e . message rescue URI :: InvalidURIError abort \"Invalid url\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "helpers [CODESPLIT] def sql_date ( time , cast , add_cast = true ) if cast == \"timestamptz\" fmt = \"%Y-%m-%d %H:%M:%S UTC\" else fmt = \"%Y-%m-%d\" end str = \"'#{time.strftime(fmt)}'\" add_cast ? \"#{str}::#{cast}\" : str end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "http : // stackoverflow . com / a / 20537829 [CODESPLIT] def primary_key query = <<-SQL SQL execute ( query , [ schema , name ] ) . map { | r | r [ \"attname\" ] } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "legacy [CODESPLIT] def fetch_settings ( trigger_name ) needs_comment = false trigger_comment = fetch_trigger ( trigger_name ) comment = trigger_comment || fetch_comment if comment field , period , cast , version = comment [ \"comment\" ] . split ( \",\" ) . map { | v | v . split ( \":\" ) . last } rescue [ ] version = version . to_i if version end unless period needs_comment = true function_def = execute ( \"SELECT pg_get_functiondef(oid) FROM pg_proc WHERE proname = $1\" , [ trigger_name ] ) [ 0 ] return [ ] unless function_def function_def = function_def [ \"pg_get_functiondef\" ] sql_format = SQL_FORMAT . find { | _ , f | function_def . include? ( \"'#{f}'\" ) } return [ ] unless sql_format period = sql_format [ 0 ] field = / \\( \\. \\w / . match ( function_def ) [ 1 ] end # backwards compatibility with 0.2.3 and earlier (pre-timestamptz support) unless cast cast = \"date\" # update comment to explicitly define cast needs_comment = true end version ||= trigger_comment ? 1 : 2 declarative = version > 1 [ period , field , cast , needs_comment , declarative , version ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Assistant service . [CODESPLIT] def message ( workspace_id : , input : nil , intents : nil , entities : nil , alternate_intents : nil , context : nil , output : nil , nodes_visited_details : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"message\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"nodes_visited_details\" => nodes_visited_details } data = { \"input\" => input , \"intents\" => intents , \"entities\" => entities , \"alternate_intents\" => alternate_intents , \"context\" => context , \"output\" => output } method_url = \"/v1/workspaces/%s/message\" % [ ERB :: Util . url_encode ( workspace_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Workspaces [CODESPLIT] def create_workspace ( name : nil , description : nil , language : nil , metadata : nil , learning_opt_out : nil , system_settings : nil , intents : nil , entities : nil , dialog_nodes : nil , counterexamples : nil ) headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"create_workspace\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"name\" => name , \"description\" => description , \"language\" => language , \"metadata\" => metadata , \"learning_opt_out\" => learning_opt_out , \"system_settings\" => system_settings , \"intents\" => intents , \"entities\" => entities , \"dialog_nodes\" => dialog_nodes , \"counterexamples\" => counterexamples } method_url = \"/v1/workspaces\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method list_workspaces ( page_limit : nil include_count : nil sort : nil cursor : nil include_audit : nil ) List workspaces . List the workspaces associated with a Watson Assistant service instance . [CODESPLIT] def list_workspaces ( page_limit : nil , include_count : nil , sort : nil , cursor : nil , include_audit : nil ) headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"list_workspaces\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"page_limit\" => page_limit , \"include_count\" => include_count , \"sort\" => sort , \"cursor\" => cursor , \"include_audit\" => include_audit } method_url = \"/v1/workspaces\" response = request ( method : \"GET\" , url : method_url , headers : headers , params : params , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_workspace ( workspace_id : name : nil description : nil language : nil metadata : nil learning_opt_out : nil system_settings : nil intents : nil entities : nil dialog_nodes : nil counterexamples : nil append : nil ) Update workspace . Update an existing workspace with new or modified data . You must provide component objects defining the content of the updated workspace . [CODESPLIT] def update_workspace ( workspace_id : , name : nil , description : nil , language : nil , metadata : nil , learning_opt_out : nil , system_settings : nil , intents : nil , entities : nil , dialog_nodes : nil , counterexamples : nil , append : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"update_workspace\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"append\" => append } data = { \"name\" => name , \"description\" => description , \"language\" => language , \"metadata\" => metadata , \"learning_opt_out\" => learning_opt_out , \"system_settings\" => system_settings , \"intents\" => intents , \"entities\" => entities , \"dialog_nodes\" => dialog_nodes , \"counterexamples\" => counterexamples } method_url = \"/v1/workspaces/%s\" % [ ERB :: Util . url_encode ( workspace_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_intent ( workspace_id : intent : new_intent : nil new_description : nil new_examples : nil ) Update intent . Update an existing intent with new or modified data . You must provide component objects defining the content of the updated intent . [CODESPLIT] def update_intent ( workspace_id : , intent : , new_intent : nil , new_description : nil , new_examples : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"intent must be provided\" ) if intent . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"update_intent\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"intent\" => new_intent , \"description\" => new_description , \"examples\" => new_examples } method_url = \"/v1/workspaces/%s/intents/%s\" % [ ERB :: Util . url_encode ( workspace_id ) , ERB :: Util . url_encode ( intent ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Entities [CODESPLIT] def create_entity ( workspace_id : , entity : , description : nil , metadata : nil , fuzzy_match : nil , values : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"entity must be provided\" ) if entity . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"create_entity\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"entity\" => entity , \"description\" => description , \"metadata\" => metadata , \"fuzzy_match\" => fuzzy_match , \"values\" => values } method_url = \"/v1/workspaces/%s/entities\" % [ ERB :: Util . url_encode ( workspace_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_entity ( workspace_id : entity : new_entity : nil new_description : nil new_metadata : nil new_fuzzy_match : nil new_values : nil ) Update entity . Update an existing entity with new or modified data . You must provide component objects defining the content of the updated entity . [CODESPLIT] def update_entity ( workspace_id : , entity : , new_entity : nil , new_description : nil , new_metadata : nil , new_fuzzy_match : nil , new_values : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"entity must be provided\" ) if entity . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"update_entity\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"entity\" => new_entity , \"description\" => new_description , \"metadata\" => new_metadata , \"fuzzy_match\" => new_fuzzy_match , \"values\" => new_values } method_url = \"/v1/workspaces/%s/entities/%s\" % [ ERB :: Util . url_encode ( workspace_id ) , ERB :: Util . url_encode ( entity ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Values [CODESPLIT] def create_value ( workspace_id : , entity : , value : , metadata : nil , value_type : nil , synonyms : nil , patterns : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"entity must be provided\" ) if entity . nil? raise ArgumentError . new ( \"value must be provided\" ) if value . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"create_value\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"value\" => value , \"metadata\" => metadata , \"type\" => value_type , \"synonyms\" => synonyms , \"patterns\" => patterns } method_url = \"/v1/workspaces/%s/entities/%s/values\" % [ ERB :: Util . url_encode ( workspace_id ) , ERB :: Util . url_encode ( entity ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_value ( workspace_id : entity : value : new_value : nil new_metadata : nil new_value_type : nil new_synonyms : nil new_patterns : nil ) Update entity value . Update an existing entity value with new or modified data . You must provide component objects defining the content of the updated entity value . [CODESPLIT] def update_value ( workspace_id : , entity : , value : , new_value : nil , new_metadata : nil , new_value_type : nil , new_synonyms : nil , new_patterns : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"entity must be provided\" ) if entity . nil? raise ArgumentError . new ( \"value must be provided\" ) if value . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"update_value\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"value\" => new_value , \"metadata\" => new_metadata , \"type\" => new_value_type , \"synonyms\" => new_synonyms , \"patterns\" => new_patterns } method_url = \"/v1/workspaces/%s/entities/%s/values/%s\" % [ ERB :: Util . url_encode ( workspace_id ) , ERB :: Util . url_encode ( entity ) , ERB :: Util . url_encode ( value ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Dialog nodes [CODESPLIT] def create_dialog_node ( workspace_id : , dialog_node : , description : nil , conditions : nil , parent : nil , previous_sibling : nil , output : nil , context : nil , metadata : nil , next_step : nil , title : nil , node_type : nil , event_name : nil , variable : nil , actions : nil , digress_in : nil , digress_out : nil , digress_out_slots : nil , user_label : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"dialog_node must be provided\" ) if dialog_node . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"create_dialog_node\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"dialog_node\" => dialog_node , \"description\" => description , \"conditions\" => conditions , \"parent\" => parent , \"previous_sibling\" => previous_sibling , \"output\" => output , \"context\" => context , \"metadata\" => metadata , \"next_step\" => next_step , \"title\" => title , \"type\" => node_type , \"event_name\" => event_name , \"variable\" => variable , \"actions\" => actions , \"digress_in\" => digress_in , \"digress_out\" => digress_out , \"digress_out_slots\" => digress_out_slots , \"user_label\" => user_label } method_url = \"/v1/workspaces/%s/dialog_nodes\" % [ ERB :: Util . url_encode ( workspace_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_dialog_node ( workspace_id : dialog_node : new_dialog_node : nil new_description : nil new_conditions : nil new_parent : nil new_previous_sibling : nil new_output : nil new_context : nil new_metadata : nil new_next_step : nil new_title : nil new_node_type : nil new_event_name : nil new_variable : nil new_actions : nil new_digress_in : nil new_digress_out : nil new_digress_out_slots : nil new_user_label : nil ) Update dialog node . Update an existing dialog node with new or modified data . [CODESPLIT] def update_dialog_node ( workspace_id : , dialog_node : , new_dialog_node : nil , new_description : nil , new_conditions : nil , new_parent : nil , new_previous_sibling : nil , new_output : nil , new_context : nil , new_metadata : nil , new_next_step : nil , new_title : nil , new_node_type : nil , new_event_name : nil , new_variable : nil , new_actions : nil , new_digress_in : nil , new_digress_out : nil , new_digress_out_slots : nil , new_user_label : nil ) raise ArgumentError . new ( \"workspace_id must be provided\" ) if workspace_id . nil? raise ArgumentError . new ( \"dialog_node must be provided\" ) if dialog_node . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"update_dialog_node\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"dialog_node\" => new_dialog_node , \"description\" => new_description , \"conditions\" => new_conditions , \"parent\" => new_parent , \"previous_sibling\" => new_previous_sibling , \"output\" => new_output , \"context\" => new_context , \"metadata\" => new_metadata , \"next_step\" => new_next_step , \"title\" => new_title , \"type\" => new_node_type , \"event_name\" => new_event_name , \"variable\" => new_variable , \"actions\" => new_actions , \"digress_in\" => new_digress_in , \"digress_out\" => new_digress_out , \"digress_out_slots\" => new_digress_out_slots , \"user_label\" => new_user_label } method_url = \"/v1/workspaces/%s/dialog_nodes/%s\" % [ ERB :: Util . url_encode ( workspace_id ) , ERB :: Util . url_encode ( dialog_node ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Logs [CODESPLIT] def list_all_logs ( filter : , sort : nil , page_limit : nil , cursor : nil ) raise ArgumentError . new ( \"filter must be provided\" ) if filter . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V1\" , \"list_all_logs\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"filter\" => filter , \"sort\" => sort , \"page_limit\" => page_limit , \"cursor\" => cursor } method_url = \"/v1/logs\" response = request ( method : \"GET\" , url : method_url , headers : headers , params : params , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Visual Recognition service . [CODESPLIT] def classify ( images_file : nil , images_filename : nil , images_file_content_type : nil , url : nil , threshold : nil , owners : nil , classifier_ids : nil , accept_language : nil ) headers = { \"Accept-Language\" => accept_language } sdk_headers = Common . new . get_sdk_headers ( \"watson_vision_combined\" , \"V3\" , \"classify\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } form_data = { } unless images_file . nil? unless images_file . instance_of? ( StringIO ) || images_file . instance_of? ( File ) images_file = images_file . respond_to? ( :to_json ) ? StringIO . new ( images_file . to_json ) : StringIO . new ( images_file ) end images_filename = images_file . path if images_filename . nil? && images_file . respond_to? ( :path ) form_data [ :images_file ] = HTTP :: FormData :: File . new ( images_file , content_type : images_file_content_type . nil? ? \"application/octet-stream\" : images_file_content_type , filename : images_filename ) end classifier_ids *= \",\" unless classifier_ids . nil? owners *= \",\" unless owners . nil? form_data [ :url ] = HTTP :: FormData :: Part . new ( url . to_s , content_type : \"text/plain\" ) unless url . nil? form_data [ :threshold ] = HTTP :: FormData :: Part . new ( threshold . to_s , content_type : \"application/json\" ) unless threshold . nil? form_data [ :owners ] = HTTP :: FormData :: Part . new ( owners , content_type : \"application/json\" ) unless owners . nil? form_data [ :classifier_ids ] = HTTP :: FormData :: Part . new ( classifier_ids , content_type : \"application/json\" ) unless classifier_ids . nil? method_url = \"/v3/classify\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Face [CODESPLIT] def detect_faces ( images_file : nil , images_filename : nil , images_file_content_type : nil , url : nil , accept_language : nil ) headers = { \"Accept-Language\" => accept_language } sdk_headers = Common . new . get_sdk_headers ( \"watson_vision_combined\" , \"V3\" , \"detect_faces\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } form_data = { } unless images_file . nil? unless images_file . instance_of? ( StringIO ) || images_file . instance_of? ( File ) images_file = images_file . respond_to? ( :to_json ) ? StringIO . new ( images_file . to_json ) : StringIO . new ( images_file ) end images_filename = images_file . path if images_filename . nil? && images_file . respond_to? ( :path ) form_data [ :images_file ] = HTTP :: FormData :: File . new ( images_file , content_type : images_file_content_type . nil? ? \"application/octet-stream\" : images_file_content_type , filename : images_filename ) end form_data [ :url ] = HTTP :: FormData :: Part . new ( url . to_s , content_type : \"text/plain\" ) unless url . nil? method_url = \"/v3/detect_faces\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method update_classifier ( classifier_id : positive_examples : nil negative_examples : nil negative_examples_filename : nil ) Update a classifier . Update a custom classifier by adding new positive or negative classes or by adding new images to existing classes . You must supply at least one set of positive or negative examples . For details see [ Updating custom classifiers ] ( https : // cloud . ibm . com / docs / services / visual - recognition / customizing . html#updating - custom - classifiers ) . [CODESPLIT] def update_classifier ( classifier_id : , positive_examples : nil , negative_examples : nil , negative_examples_filename : nil ) raise ArgumentError . new ( \"classifier_id must be provided\" ) if classifier_id . nil? raise ArgumentError . new ( \"positive_examples must be a hash\" ) unless positive_examples . nil? || positive_examples . is_a? ( Hash ) headers = { } sdk_headers = Common . new . get_sdk_headers ( \"watson_vision_combined\" , \"V3\" , \"update_classifier\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } form_data = { } positive_examples &. each do | key , value | part_name = \"%s_positive_examples\" % key . to_s unless value . instance_of? ( StringIO ) || value . instance_of? ( File ) value = value . respond_to? ( :to_json ) ? StringIO . new ( value . to_json ) : StringIO . new ( value ) end filename = value . path if value . respond_to? ( :path ) form_data [ part_name . to_sym ] = HTTP :: FormData :: File . new ( value , content_type : \"application/octet-stream\" , filename : filename ) end unless negative_examples . nil? unless negative_examples . instance_of? ( StringIO ) || negative_examples . instance_of? ( File ) negative_examples = negative_examples . respond_to? ( :to_json ) ? StringIO . new ( negative_examples . to_json ) : StringIO . new ( negative_examples ) end negative_examples_filename = negative_examples . path if negative_examples_filename . nil? && negative_examples . respond_to? ( :path ) form_data [ :negative_examples ] = HTTP :: FormData :: File . new ( negative_examples , content_type : \"application/octet-stream\" , filename : negative_examples_filename ) end method_url = \"/v3/classifiers/%s\" % [ ERB :: Util . url_encode ( classifier_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Manage classifiers [CODESPLIT] def create_classifier ( metadata : , training_data : ) raise ArgumentError . new ( \"metadata must be provided\" ) if metadata . nil? raise ArgumentError . new ( \"training_data must be provided\" ) if training_data . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"natural_language_classifier\" , \"V1\" , \"create_classifier\" ) headers . merge! ( sdk_headers ) form_data = { } unless metadata . instance_of? ( StringIO ) || metadata . instance_of? ( File ) metadata = metadata . respond_to? ( :to_json ) ? StringIO . new ( metadata . to_json ) : StringIO . new ( metadata ) end form_data [ :training_metadata ] = HTTP :: FormData :: File . new ( metadata , content_type : \"application/json\" , filename : metadata . respond_to? ( :path ) ? metadata . path : nil ) unless training_data . instance_of? ( StringIO ) || training_data . instance_of? ( File ) training_data = training_data . respond_to? ( :to_json ) ? StringIO . new ( training_data . to_json ) : StringIO . new ( training_data ) end form_data [ :training_data ] = HTTP :: FormData :: File . new ( training_data , content_type : \"text/csv\" , filename : training_data . respond_to? ( :path ) ? training_data . path : nil ) method_url = \"/v1/classifiers\" response = request ( method : \"POST\" , url : method_url , headers : headers , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Personality Insights service . [CODESPLIT] def profile ( content : , accept : , content_language : nil , accept_language : nil , raw_scores : nil , csv_headers : nil , consumption_preferences : nil , content_type : nil ) raise ArgumentError . new ( \"content must be provided\" ) if content . nil? raise ArgumentError . new ( \"accept must be provided\" ) if accept . nil? headers = { \"Accept\" => accept , \"Content-Language\" => content_language , \"Accept-Language\" => accept_language , \"Content-Type\" => content_type } sdk_headers = Common . new . get_sdk_headers ( \"personality_insights\" , \"V3\" , \"profile\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"raw_scores\" => raw_scores , \"csv_headers\" => csv_headers , \"consumption_preferences\" => consumption_preferences } if content_type . start_with? ( \"application/json\" ) && content . instance_of? ( Hash ) data = content . to_json else data = content end method_url = \"/v3/profile\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Synthesis [CODESPLIT] def synthesize ( text : , voice : nil , customization_id : nil , accept : nil ) raise ArgumentError . new ( \"text must be provided\" ) if text . nil? headers = { \"Accept\" => accept } sdk_headers = Common . new . get_sdk_headers ( \"text_to_speech\" , \"V1\" , \"synthesize\" ) headers . merge! ( sdk_headers ) params = { \"voice\" => voice , \"customization_id\" => customization_id } data = { \"text\" => text } method_url = \"/v1/synthesize\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : false ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pronunciation [CODESPLIT] def get_pronunciation ( text : , voice : nil , format : nil , customization_id : nil ) raise ArgumentError . new ( \"text must be provided\" ) if text . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"text_to_speech\" , \"V1\" , \"get_pronunciation\" ) headers . merge! ( sdk_headers ) params = { \"text\" => text , \"voice\" => voice , \"format\" => format , \"customization_id\" => customization_id } method_url = \"/v1/pronunciation\" response = request ( method : \"GET\" , url : method_url , headers : headers , params : params , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Custom words [CODESPLIT] def add_word ( customization_id : , word : , translation : , part_of_speech : nil ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"word must be provided\" ) if word . nil? raise ArgumentError . new ( \"translation must be provided\" ) if translation . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"text_to_speech\" , \"V1\" , \"add_word\" ) headers . merge! ( sdk_headers ) data = { \"translation\" => translation , \"part_of_speech\" => part_of_speech } method_url = \"/v1/customizations/%s/words/%s\" % [ ERB :: Util . url_encode ( customization_id ) , ERB :: Util . url_encode ( word ) ] request ( method : \"PUT\" , url : method_url , headers : headers , json : data , accept_json : false ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "User data [CODESPLIT] def delete_user_data ( customer_id : ) raise ArgumentError . new ( \"customer_id must be provided\" ) if customer_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"text_to_speech\" , \"V1\" , \"delete_user_data\" ) headers . merge! ( sdk_headers ) params = { \"customer_id\" => customer_id } method_url = \"/v1/user_data\" request ( method : \"DELETE\" , url : method_url , headers : headers , params : params , accept_json : false ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Compare Comply service . [CODESPLIT] def convert_to_html ( file : , filename : nil , file_content_type : nil , model : nil ) raise ArgumentError . new ( \"file must be provided\" ) if file . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"compare-comply\" , \"V1\" , \"convert_to_html\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"model\" => model } form_data = { } unless file . instance_of? ( StringIO ) || file . instance_of? ( File ) file = file . respond_to? ( :to_json ) ? StringIO . new ( file . to_json ) : StringIO . new ( file ) end filename = file . path if filename . nil? && file . respond_to? ( :path ) form_data [ :file ] = HTTP :: FormData :: File . new ( file , content_type : file_content_type . nil? ? \"application/octet-stream\" : file_content_type , filename : filename ) method_url = \"/v1/html_conversion\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Comparison [CODESPLIT] def compare_documents ( file_1 : , file_2 : , file_1_content_type : nil , file_2_content_type : nil , file_1_label : nil , file_2_label : nil , model : nil ) raise ArgumentError . new ( \"file_1 must be provided\" ) if file_1 . nil? raise ArgumentError . new ( \"file_2 must be provided\" ) if file_2 . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"compare-comply\" , \"V1\" , \"compare_documents\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"file_1_label\" => file_1_label , \"file_2_label\" => file_2_label , \"model\" => model } form_data = { } unless file_1 . instance_of? ( StringIO ) || file_1 . instance_of? ( File ) file_1 = file_1 . respond_to? ( :to_json ) ? StringIO . new ( file_1 . to_json ) : StringIO . new ( file_1 ) end form_data [ :file_1 ] = HTTP :: FormData :: File . new ( file_1 , content_type : file_1_content_type . nil? ? \"application/octet-stream\" : file_1_content_type , filename : file_1 . respond_to? ( :path ) ? file_1 . path : nil ) unless file_2 . instance_of? ( StringIO ) || file_2 . instance_of? ( File ) file_2 = file_2 . respond_to? ( :to_json ) ? StringIO . new ( file_2 . to_json ) : StringIO . new ( file_2 ) end form_data [ :file_2 ] = HTTP :: FormData :: File . new ( file_2 , content_type : file_2_content_type . nil? ? \"application/octet-stream\" : file_2_content_type , filename : file_2 . respond_to? ( :path ) ? file_2 . path : nil ) method_url = \"/v1/comparison\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Feedback [CODESPLIT] def add_feedback ( feedback_data : , user_id : nil , comment : nil ) raise ArgumentError . new ( \"feedback_data must be provided\" ) if feedback_data . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"compare-comply\" , \"V1\" , \"add_feedback\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"feedback_data\" => feedback_data , \"user_id\" => user_id , \"comment\" => comment } method_url = \"/v1/feedback\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Batches [CODESPLIT] def create_batch ( function : , input_credentials_file : , input_bucket_location : , input_bucket_name : , output_credentials_file : , output_bucket_location : , output_bucket_name : , model : nil ) raise ArgumentError . new ( \"function must be provided\" ) if function . nil? raise ArgumentError . new ( \"input_credentials_file must be provided\" ) if input_credentials_file . nil? raise ArgumentError . new ( \"input_bucket_location must be provided\" ) if input_bucket_location . nil? raise ArgumentError . new ( \"input_bucket_name must be provided\" ) if input_bucket_name . nil? raise ArgumentError . new ( \"output_credentials_file must be provided\" ) if output_credentials_file . nil? raise ArgumentError . new ( \"output_bucket_location must be provided\" ) if output_bucket_location . nil? raise ArgumentError . new ( \"output_bucket_name must be provided\" ) if output_bucket_name . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"compare-comply\" , \"V1\" , \"create_batch\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"function\" => function , \"model\" => model } form_data = { } unless input_credentials_file . instance_of? ( StringIO ) || input_credentials_file . instance_of? ( File ) input_credentials_file = input_credentials_file . respond_to? ( :to_json ) ? StringIO . new ( input_credentials_file . to_json ) : StringIO . new ( input_credentials_file ) end form_data [ :input_credentials_file ] = HTTP :: FormData :: File . new ( input_credentials_file , content_type : \"application/json\" , filename : input_credentials_file . respond_to? ( :path ) ? input_credentials_file . path : nil ) form_data [ :input_bucket_location ] = HTTP :: FormData :: Part . new ( input_bucket_location . to_s , content_type : \"text/plain\" ) form_data [ :input_bucket_name ] = HTTP :: FormData :: Part . new ( input_bucket_name . to_s , content_type : \"text/plain\" ) unless output_credentials_file . instance_of? ( StringIO ) || output_credentials_file . instance_of? ( File ) output_credentials_file = output_credentials_file . respond_to? ( :to_json ) ? StringIO . new ( output_credentials_file . to_json ) : StringIO . new ( output_credentials_file ) end form_data [ :output_credentials_file ] = HTTP :: FormData :: File . new ( output_credentials_file , content_type : \"application/json\" , filename : output_credentials_file . respond_to? ( :path ) ? output_credentials_file . path : nil ) form_data [ :output_bucket_location ] = HTTP :: FormData :: Part . new ( output_bucket_location . to_s , content_type : \"text/plain\" ) form_data [ :output_bucket_name ] = HTTP :: FormData :: Part . new ( output_bucket_name . to_s , content_type : \"text/plain\" ) method_url = \"/v1/batches\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Tone Analyzer service . [CODESPLIT] def tone ( tone_input : , sentences : nil , tones : nil , content_language : nil , accept_language : nil , content_type : nil ) raise ArgumentError . new ( \"tone_input must be provided\" ) if tone_input . nil? headers = { \"Content-Language\" => content_language , \"Accept-Language\" => accept_language , \"Content-Type\" => content_type } sdk_headers = Common . new . get_sdk_headers ( \"tone_analyzer\" , \"V3\" , \"tone\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"sentences\" => sentences , \"tones\" => tones . to_a } if content_type . start_with? ( \"application/json\" ) && tone_input . instance_of? ( Hash ) data = tone_input . to_json else data = tone_input end method_url = \"/v3/tone\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method tone_chat ( utterances : content_language : nil accept_language : nil ) Analyze customer engagement tone . Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations . For each utterance of a conversation the method reports the most prevalent subset of the following seven tones : sad frustrated satisfied excited polite impolite and sympathetic . [CODESPLIT] def tone_chat ( utterances : , content_language : nil , accept_language : nil ) raise ArgumentError . new ( \"utterances must be provided\" ) if utterances . nil? headers = { \"Content-Language\" => content_language , \"Accept-Language\" => accept_language } sdk_headers = Common . new . get_sdk_headers ( \"tone_analyzer\" , \"V3\" , \"tone_chat\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"utterances\" => utterances } method_url = \"/v3/tone_chat\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Language Translator service . [CODESPLIT] def translate ( text : , model_id : nil , source : nil , target : nil ) raise ArgumentError . new ( \"text must be provided\" ) if text . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"language_translator\" , \"V3\" , \"translate\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"text\" => text , \"model_id\" => model_id , \"source\" => source , \"target\" => target } method_url = \"/v3/translate\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Identification [CODESPLIT] def identify ( text : ) raise ArgumentError . new ( \"text must be provided\" ) if text . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"language_translator\" , \"V3\" , \"identify\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = text headers [ \"Content-Type\" ] = \"text/plain\" method_url = \"/v3/identify\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Models [CODESPLIT] def create_model ( base_model_id : , forced_glossary : nil , parallel_corpus : nil , name : nil ) raise ArgumentError . new ( \"base_model_id must be provided\" ) if base_model_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"language_translator\" , \"V3\" , \"create_model\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"base_model_id\" => base_model_id , \"name\" => name } form_data = { } unless forced_glossary . nil? unless forced_glossary . instance_of? ( StringIO ) || forced_glossary . instance_of? ( File ) forced_glossary = forced_glossary . respond_to? ( :to_json ) ? StringIO . new ( forced_glossary . to_json ) : StringIO . new ( forced_glossary ) end form_data [ :forced_glossary ] = HTTP :: FormData :: File . new ( forced_glossary , content_type : \"application/octet-stream\" , filename : forced_glossary . respond_to? ( :path ) ? forced_glossary . path : nil ) end unless parallel_corpus . nil? unless parallel_corpus . instance_of? ( StringIO ) || parallel_corpus . instance_of? ( File ) parallel_corpus = parallel_corpus . respond_to? ( :to_json ) ? StringIO . new ( parallel_corpus . to_json ) : StringIO . new ( parallel_corpus ) end form_data [ :parallel_corpus ] = HTTP :: FormData :: File . new ( parallel_corpus , content_type : \"application/octet-stream\" , filename : parallel_corpus . respond_to? ( :path ) ? parallel_corpus . path : nil ) end method_url = \"/v3/models\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Natural Language Understanding service . [CODESPLIT] def analyze ( features : , text : nil , html : nil , url : nil , clean : nil , xpath : nil , fallback_to_raw : nil , return_analyzed_text : nil , language : nil , limit_text_characters : nil ) raise ArgumentError . new ( \"features must be provided\" ) if features . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"natural-language-understanding\" , \"V1\" , \"analyze\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"features\" => features , \"text\" => text , \"html\" => html , \"url\" => url , \"clean\" => clean , \"xpath\" => xpath , \"fallback_to_raw\" => fallback_to_raw , \"return_analyzed_text\" => return_analyzed_text , \"language\" => language , \"limit_text_characters\" => limit_text_characters } method_url = \"/v1/analyze\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Speech to Text service . [CODESPLIT] def get_model ( model_id : ) raise ArgumentError . new ( \"model_id must be provided\" ) if model_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"get_model\" ) headers . merge! ( sdk_headers ) method_url = \"/v1/models/%s\" % [ ERB :: Util . url_encode ( model_id ) ] response = request ( method : \"GET\" , url : method_url , headers : headers , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method recognize_using_websocket ( content_type : recognize_callback : audio : nil chunk_data : false model : nil customization_id : nil acoustic_customization_id : nil customization_weight : nil base_model_version : nil inactivity_timeout : nil interim_results : nil keywords : nil keywords_threshold : nil max_alternatives : nil word_alternatives_threshold : nil word_confidence : nil timestamps : nil profanity_filter : nil smart_formatting : nil speaker_labels : nil ) Sends audio for speech recognition using web sockets . @param content_type [ String ] The type of the input : audio / basic audio / flac audio / l16 audio / mp3 audio / mpeg audio / mulaw audio / ogg audio / ogg ; codecs = opus audio / ogg ; codecs = vorbis audio / wav audio / webm audio / webm ; codecs = opus audio / webm ; codecs = vorbis or multipart / form - data . @param recognize_callback [ RecognizeCallback ] The instance handling events returned from the service . @param audio [ IO ] Audio to transcribe in the format specified by the Content - Type header . @param chunk_data [ Boolean ] If true then the WebSocketClient will expect to receive data in chunks rather than as a single audio file @param model [ String ] The identifier of the model to be used for the recognition request . @param customization_id [ String ] The GUID of a custom language model that is to be used with the request . The base model of the specified custom language model must match the model specified with the model parameter . You must make the request with service credentials created for the instance of the service that owns the custom model . By default no custom language model is used . @param acoustic_customization_id [ String ] The GUID of a custom acoustic model that is to be used with the request . The base model of the specified custom acoustic model must match the model specified with the model parameter . You must make the request with service credentials created for the instance of the service that owns the custom model . By default no custom acoustic model is used . @param language_customization_id [ String ] The GUID of a custom language model that is to be used with the request . The base model of the specified custom language model must match the model specified with the model parameter . You must make the request with service credentials created for the instance of the service that owns the custom model . By default no custom language model is used . @param customization_weight [ Float ] If you specify a customization_id with the request you can use the customization_weight parameter to tell the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition . Specify a value between 0 . 0 and 1 . 0 . Unless a different customization weight was specified for the custom model when it was trained the default value is 0 . 3 . A customization weight that you specify overrides a weight that was specified when the custom model was trained . The default value yields the best performance in general . Assign a higher value if your audio makes frequent use of OOV words from the custom model . Use caution when setting the weight : a higher value can improve the accuracy of phrases from the custom model s domain but it can negatively affect performance on non - domain phrases . @param base_model_version [ String ] The version of the specified base model that is to be used for speech recognition . Multiple versions of a base model can exist when a model is updated for internal improvements . The parameter is intended primarily for use with custom models that have been upgraded for a new base model . The default value depends on whether the parameter is used with or without a custom model . For more information see [ Base model version ] ( https : // console . bluemix . net / docs / services / speech - to - text / input . html#version ) . @param inactivity_timeout [ Integer ] The time in seconds after which if only silence ( no speech ) is detected in submitted audio the connection is closed with a 400 error . Useful for stopping audio submission from a live microphone when a user simply walks away . Use - 1 for infinity . @param interim_results [ Boolean ] Send back non - final previews of each sentence as it is being processed . These results are ignored in text mode . @param keywords [ Array<String > ] Array of keyword strings to spot in the audio . Each keyword string can include one or more tokens . Keywords are spotted only in the final hypothesis not in interim results . If you specify any keywords you must also specify a keywords threshold . Omit the parameter or specify an empty array if you do not need to spot keywords . @param keywords_threshold [ Float ] Confidence value that is the lower bound for spotting a keyword . A word is considered to match a keyword if its confidence is greater than or equal to the threshold . Specify a probability between 0 and 1 inclusive . No keyword spotting is performed if you omit the parameter . If you specify a threshold you must also specify one or more keywords . @param max_alternatives [ Integer ] Maximum number of alternative transcripts to be returned . By default a single transcription is returned . @param word_alternatives_threshold [ Float ] Confidence value that is the lower bound for identifying a hypothesis as a possible word alternative ( also known as \\ Confusion Networks \\ ) . An alternative word is considered if its confidence is greater than or equal to the threshold . Specify a probability between 0 and 1 inclusive . No alternative words are computed if you omit the parameter . @param word_confidence [ Boolean ] If true confidence measure per word is returned . @param timestamps [ Boolean ] If true time alignment for each word is returned . @param profanity_filter [ Boolean ] If true ( the default ) filters profanity from all output except for keyword results by replacing inappropriate words with a series of asterisks . Set the parameter to false to return results with no censoring . Applies to US English transcription only . @param smart_formatting [ Boolean ] If true converts dates times series of digits and numbers phone numbers currency values and Internet addresses into more readable conventional representations in the final transcript of a recognition request . If false ( the default ) no formatting is performed . Applies to US English transcription only . @param speaker_labels [ Boolean ] Indicates whether labels that identify which words were spoken by which participants in a multi - person exchange are to be included in the response . The default is false ; no speaker labels are returned . Setting speaker_labels to true forces the timestamps parameter to be true regardless of whether you specify false for the parameter . To determine whether a language model supports speaker labels use the GET / v1 / models method and check that the attribute speaker_labels is set to true . You can also refer to [ Speaker labels ] ( https : // console . bluemix . net / docs / services / speech - to - text / output . html#speaker_labels ) . @param grammar_name [ String ] The name of a grammar that is to be used with the recognition request . If you specify a grammar you must also use the language_customization_id parameter to specify the name of the custom language model for which the grammar is defined . The service recognizes only strings that are recognized by the specified grammar ; it does not recognize other custom words from the model s words resource . See [ Grammars ] ( https : // cloud . ibm . com / docs / services / speech - to - text / output . html ) . @param redaction [ Boolean ] If true the service redacts or masks numeric data from final transcripts . The feature redacts any number that has three or more consecutive digits by replacing each digit with an X character . It is intended to redact sensitive numeric data such as credit card numbers . By default the service performs no redaction . [CODESPLIT] def recognize_using_websocket ( content_type : nil , recognize_callback : , audio : nil , chunk_data : false , model : nil , language_customization_id : nil , customization_id : nil , acoustic_customization_id : nil , customization_weight : nil , base_model_version : nil , inactivity_timeout : nil , interim_results : nil , keywords : nil , keywords_threshold : nil , max_alternatives : nil , word_alternatives_threshold : nil , word_confidence : nil , timestamps : nil , profanity_filter : nil , smart_formatting : nil , speaker_labels : nil , grammar_name : nil , redaction : nil ) raise ArgumentError ( \"Audio must be provided\" ) if audio . nil? && ! chunk_data raise ArgumentError ( \"Recognize callback must be provided\" ) if recognize_callback . nil? raise TypeError ( \"Callback is not a derived class of RecognizeCallback\" ) unless recognize_callback . is_a? ( IBMWatson :: RecognizeCallback ) require_relative ( \"./websocket/speech_to_text_websocket_listener.rb\" ) headers = { } headers = conn . default_options . headers . to_hash unless conn . default_options . headers . to_hash . empty? if ! token_manager . nil? access_token = token_manager . token headers [ \"Authorization\" ] = \"Bearer #{access_token}\" elsif ! username . nil? && ! password . nil? headers [ \"Authorization\" ] = \"Basic \" + Base64 . strict_encode64 ( \"#{username}:#{password}\" ) end url = @url . gsub ( \"https:\" , \"wss:\" ) params = { \"model\" => model , \"customization_id\" => customization_id , \"langauge_customization_id\" => language_customization_id , \"acoustic_customization_id\" => acoustic_customization_id , \"customization_weight\" => customization_weight , \"base_model_version\" => base_model_version } params . delete_if { | _ , v | v . nil? } url += \"/v1/recognize?\" + HTTP :: URI . form_encode ( params ) options = { \"content_type\" => content_type , \"inactivity_timeout\" => inactivity_timeout , \"interim_results\" => interim_results , \"keywords\" => keywords , \"keywords_threshold\" => keywords_threshold , \"max_alternatives\" => max_alternatives , \"word_alternatives_threshold\" => word_alternatives_threshold , \"word_confidence\" => word_confidence , \"timestamps\" => timestamps , \"profanity_filter\" => profanity_filter , \"smart_formatting\" => smart_formatting , \"speaker_labels\" => speaker_labels , \"grammar_name\" => grammar_name , \"redaction\" => redaction } options . delete_if { | _ , v | v . nil? } WebSocketClient . new ( audio : audio , chunk_data : chunk_data , options : options , recognize_callback : recognize_callback , url : url , headers : headers , disable_ssl_verification : @disable_ssl_verification ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nocov : [CODESPLIT] def recognize_with_websocket ( content_type : , recognize_callback : , audio : nil , chunk_data : false , model : nil , customization_id : nil , acoustic_customization_id : nil , customization_weight : nil , base_model_version : nil , inactivity_timeout : nil , interim_results : nil , keywords : nil , keywords_threshold : nil , max_alternatives : nil , word_alternatives_threshold : nil , word_confidence : nil , timestamps : nil , profanity_filter : nil , smart_formatting : nil , speaker_labels : nil ) Kernel . warn ( \"[DEPRECATION] `recognize_with_websocket` is deprecated and will be removed in the next major release. Please use `recognize_using_websocket` instead.\" ) recognize_using_websocket ( audio : audio , chunk_data : chunk_data , content_type : content_type , model : model , recognize_callback : recognize_callback , customization_id : customization_id , acoustic_customization_id : acoustic_customization_id , customization_weight : customization_weight , base_model_version : base_model_version , inactivity_timeout : inactivity_timeout , interim_results : interim_results , keywords : keywords , keywords_threshold : keywords_threshold , max_alternatives : max_alternatives , word_alternatives_threshold : word_alternatives_threshold , word_confidence : word_confidence , timestamps : timestamps , profanity_filter : profanity_filter , smart_formatting : smart_formatting , speaker_labels : speaker_labels ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method create_job ( audio : model : nil callback_url : nil events : nil user_token : nil results_ttl : nil language_customization_id : nil acoustic_customization_id : nil base_model_version : nil customization_weight : nil inactivity_timeout : nil keywords : nil keywords_threshold : nil max_alternatives : nil word_alternatives_threshold : nil word_confidence : nil timestamps : nil profanity_filter : nil smart_formatting : nil speaker_labels : nil customization_id : nil grammar_name : nil redaction : nil content_type : nil ) Create a job . Creates a job for a new asynchronous recognition request . The job is owned by the instance of the service whose credentials are used to create it . How you learn the status and results of a job depends on the parameters you include with the job creation request : * By callback notification : Include the callback_url parameter to specify a URL to which the service is to send callback notifications when the status of the job changes . Optionally you can also include the events and user_token parameters to subscribe to specific events and to specify a string that is to be included with each notification for the job . * By polling the service : Omit the callback_url events and user_token parameters . You must then use the ** Check jobs ** or ** Check a job ** methods to check the status of the job using the latter to retrieve the results when the job is complete . [CODESPLIT] def create_job ( audio : , model : nil , callback_url : nil , events : nil , user_token : nil , results_ttl : nil , language_customization_id : nil , acoustic_customization_id : nil , base_model_version : nil , customization_weight : nil , inactivity_timeout : nil , keywords : nil , keywords_threshold : nil , max_alternatives : nil , word_alternatives_threshold : nil , word_confidence : nil , timestamps : nil , profanity_filter : nil , smart_formatting : nil , speaker_labels : nil , customization_id : nil , grammar_name : nil , redaction : nil , content_type : nil ) raise ArgumentError . new ( \"audio must be provided\" ) if audio . nil? headers = { \"Content-Type\" => content_type } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"create_job\" ) headers . merge! ( sdk_headers ) params = { \"model\" => model , \"callback_url\" => callback_url , \"events\" => events , \"user_token\" => user_token , \"results_ttl\" => results_ttl , \"language_customization_id\" => language_customization_id , \"acoustic_customization_id\" => acoustic_customization_id , \"base_model_version\" => base_model_version , \"customization_weight\" => customization_weight , \"inactivity_timeout\" => inactivity_timeout , \"keywords\" => keywords . to_a , \"keywords_threshold\" => keywords_threshold , \"max_alternatives\" => max_alternatives , \"word_alternatives_threshold\" => word_alternatives_threshold , \"word_confidence\" => word_confidence , \"timestamps\" => timestamps , \"profanity_filter\" => profanity_filter , \"smart_formatting\" => smart_formatting , \"speaker_labels\" => speaker_labels , \"customization_id\" => customization_id , \"grammar_name\" => grammar_name , \"redaction\" => redaction } data = audio method_url = \"/v1/recognitions\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method register_callback ( callback_url : user_secret : nil ) Register a callback . Registers a callback URL with the service for use with subsequent asynchronous recognition requests . The service attempts to register or white - list the callback URL if it is not already registered by sending a GET request to the callback URL . The service passes a random alphanumeric challenge string via the challenge_string parameter of the request . The request includes an Accept header that specifies text / plain as the required response type . [CODESPLIT] def register_callback ( callback_url : , user_secret : nil ) raise ArgumentError . new ( \"callback_url must be provided\" ) if callback_url . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"register_callback\" ) headers . merge! ( sdk_headers ) params = { \"callback_url\" => callback_url , \"user_secret\" => user_secret } method_url = \"/v1/register_callback\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Custom corpora [CODESPLIT] def add_corpus ( customization_id : , corpus_name : , corpus_file : , allow_overwrite : nil ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"corpus_name must be provided\" ) if corpus_name . nil? raise ArgumentError . new ( \"corpus_file must be provided\" ) if corpus_file . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"add_corpus\" ) headers . merge! ( sdk_headers ) params = { \"allow_overwrite\" => allow_overwrite } form_data = { } unless corpus_file . instance_of? ( StringIO ) || corpus_file . instance_of? ( File ) corpus_file = corpus_file . respond_to? ( :to_json ) ? StringIO . new ( corpus_file . to_json ) : StringIO . new ( corpus_file ) end form_data [ :corpus_file ] = HTTP :: FormData :: File . new ( corpus_file , content_type : \"text/plain\" , filename : corpus_file . respond_to? ( :path ) ? corpus_file . path : nil ) method_url = \"/v1/customizations/%s/corpora/%s\" % [ ERB :: Util . url_encode ( customization_id ) , ERB :: Util . url_encode ( corpus_name ) ] request ( method : \"POST\" , url : method_url , headers : headers , params : params , form : form_data , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Custom words [CODESPLIT] def add_word ( customization_id : , word_name : , word : nil , sounds_like : nil , display_as : nil ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"word_name must be provided\" ) if word_name . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"add_word\" ) headers . merge! ( sdk_headers ) data = { \"word\" => word , \"sounds_like\" => sounds_like , \"display_as\" => display_as } method_url = \"/v1/customizations/%s/words/%s\" % [ ERB :: Util . url_encode ( customization_id ) , ERB :: Util . url_encode ( word_name ) ] request ( method : \"PUT\" , url : method_url , headers : headers , json : data , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method add_words ( customization_id : words : ) Add custom words . Adds one or more custom words to a custom language model . The service populates the words resource for a custom model with out - of - vocabulary ( OOV ) words from each corpus or grammar that is added to the model . You can use this method to add additional words or to modify existing words in the words resource . The words resource for a model can contain a maximum of 30 thousand custom ( OOV ) words . This includes words that the service extracts from corpora and grammars and words that you add directly . [CODESPLIT] def add_words ( customization_id : , words : ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"words must be provided\" ) if words . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"add_words\" ) headers . merge! ( sdk_headers ) data = { \"words\" => words } method_url = \"/v1/customizations/%s/words\" % [ ERB :: Util . url_encode ( customization_id ) ] request ( method : \"POST\" , url : method_url , headers : headers , json : data , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Custom grammars [CODESPLIT] def add_grammar ( customization_id : , grammar_name : , grammar_file : , content_type : , allow_overwrite : nil ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"grammar_name must be provided\" ) if grammar_name . nil? raise ArgumentError . new ( \"grammar_file must be provided\" ) if grammar_file . nil? raise ArgumentError . new ( \"content_type must be provided\" ) if content_type . nil? headers = { \"Content-Type\" => content_type } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"add_grammar\" ) headers . merge! ( sdk_headers ) params = { \"allow_overwrite\" => allow_overwrite } data = grammar_file method_url = \"/v1/customizations/%s/grammars/%s\" % [ ERB :: Util . url_encode ( customization_id ) , ERB :: Util . url_encode ( grammar_name ) ] request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Custom audio resources [CODESPLIT] def add_audio ( customization_id : , audio_name : , audio_resource : , contained_content_type : nil , allow_overwrite : nil , content_type : nil ) raise ArgumentError . new ( \"customization_id must be provided\" ) if customization_id . nil? raise ArgumentError . new ( \"audio_name must be provided\" ) if audio_name . nil? raise ArgumentError . new ( \"audio_resource must be provided\" ) if audio_resource . nil? headers = { \"Contained-Content-Type\" => contained_content_type , \"Content-Type\" => content_type } sdk_headers = Common . new . get_sdk_headers ( \"speech_to_text\" , \"V1\" , \"add_audio\" ) headers . merge! ( sdk_headers ) params = { \"allow_overwrite\" => allow_overwrite } data = audio_resource method_url = \"/v1/acoustic_customizations/%s/audio/%s\" % [ ERB :: Util . url_encode ( customization_id ) , ERB :: Util . url_encode ( audio_name ) ] request ( method : \"POST\" , url : method_url , headers : headers , params : params , data : data , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method delete_session ( assistant_id : session_id : ) Delete session . Deletes a session explicitly before it times out . @param assistant_id [ String ] Unique identifier of the assistant . You can find the assistant ID of an assistant on the ** Assistants ** tab of the Watson Assistant tool . For information about creating assistants see the [ documentation ] ( https : // console . bluemix . net / docs / services / assistant / assistant - add . html#assistant - add - task ) . [CODESPLIT] def delete_session ( assistant_id : , session_id : ) raise ArgumentError . new ( \"assistant_id must be provided\" ) if assistant_id . nil? raise ArgumentError . new ( \"session_id must be provided\" ) if session_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V2\" , \"delete_session\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } method_url = \"/v2/assistants/%s/sessions/%s\" % [ ERB :: Util . url_encode ( assistant_id ) , ERB :: Util . url_encode ( session_id ) ] request ( method : \"DELETE\" , url : method_url , headers : headers , params : params , accept_json : true ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Message [CODESPLIT] def message ( assistant_id : , session_id : , input : nil , context : nil ) raise ArgumentError . new ( \"assistant_id must be provided\" ) if assistant_id . nil? raise ArgumentError . new ( \"session_id must be provided\" ) if session_id . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"conversation\" , \"V2\" , \"message\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"input\" => input , \"context\" => context } method_url = \"/v2/assistants/%s/sessions/%s/message\" % [ ERB :: Util . url_encode ( assistant_id ) , ERB :: Util . url_encode ( session_id ) ] response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( args ) Construct a new client for the Discovery service . [CODESPLIT] def create_environment ( name : , description : nil , size : nil ) raise ArgumentError . new ( \"name must be provided\" ) if name . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"discovery\" , \"V1\" , \"create_environment\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"name\" => name , \"description\" => description , \"size\" => size } method_url = \"/v1/environments\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method federated_query_notices ( environment_id : collection_ids : filter : nil query : nil natural_language_query : nil aggregation : nil count : nil return_fields : nil offset : nil sort : nil highlight : nil deduplicate_field : nil similar : nil similar_document_ids : nil similar_fields : nil ) Query multiple collection system notices . Queries for notices ( errors or warnings ) that might have been generated by the system . Notices are generated when ingesting documents and performing relevance training . See the [ Discovery service documentation ] ( https : // cloud . ibm . com / docs / services / discovery?topic = discovery - query - concepts#query - concepts ) for more details on the query language . @param environment_id [ String ] The ID of the environment . @param collection_ids [ Array [ String ]] A comma - separated list of collection IDs to be queried against . @param filter [ String ] A cacheable query that excludes documents that don t mention the query content . Filter searches are better for metadata - type searches and for assessing the concepts in the data set . @param query [ String ] A query search returns all documents in your data set with full enrichments and full text but with the most relevant documents listed first . Use a query search when you want to find the most relevant search results . You cannot use ** natural_language_query ** and ** query ** at the same time . @param natural_language_query [ String ] A natural language query that returns relevant documents by utilizing training data and natural language understanding . You cannot use ** natural_language_query ** and ** query ** at the same time . @param aggregation [ String ] An aggregation search that returns an exact answer by combining query search with filters . Useful for applications to build lists tables and time series . For a full list of possible aggregations see the Query reference . @param count [ Fixnum ] Number of results to return . The maximum for the ** count ** and ** offset ** values together in any one query is ** 10000 ** . @param return_fields [ Array [ String ]] A comma - separated list of the portion of the document hierarchy to return . @param offset [ Fixnum ] The number of query results to skip at the beginning . For example if the total number of results that are returned is 10 and the offset is 8 it returns the last two results . The maximum for the ** count ** and ** offset ** values together in any one query is ** 10000 ** . @param sort [ Array [ String ]] A comma - separated list of fields in the document to sort on . You can optionally specify a sort direction by prefixing the field with - for descending or + for ascending . Ascending is the default sort direction if no prefix is specified . @param highlight [ Boolean ] When true a highlight field is returned for each result which contains the fields which match the query with <em > < / em > tags around the matching query terms . @param deduplicate_field [ String ] When specified duplicate results based on the field specified are removed from the returned results . Duplicate comparison is limited to the current query only ** offset ** is not considered . This parameter is currently Beta functionality . @param similar [ Boolean ] When true results are returned based on their similarity to the document IDs specified in the ** similar . document_ids ** parameter . @param similar_document_ids [ Array [ String ]] A comma - separated list of document IDs to find similar documents . [CODESPLIT] def federated_query_notices ( environment_id : , collection_ids : , filter : nil , query : nil , natural_language_query : nil , aggregation : nil , count : nil , return_fields : nil , offset : nil , sort : nil , highlight : nil , deduplicate_field : nil , similar : nil , similar_document_ids : nil , similar_fields : nil ) raise ArgumentError . new ( \"environment_id must be provided\" ) if environment_id . nil? raise ArgumentError . new ( \"collection_ids must be provided\" ) if collection_ids . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"discovery\" , \"V1\" , \"federated_query_notices\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version , \"collection_ids\" => collection_ids . to_a , \"filter\" => filter , \"query\" => query , \"natural_language_query\" => natural_language_query , \"aggregation\" => aggregation , \"count\" => count , \"return\" => return_fields . to_a , \"offset\" => offset , \"sort\" => sort . to_a , \"highlight\" => highlight , \"deduplicate.field\" => deduplicate_field , \"similar\" => similar , \"similar.document_ids\" => similar_document_ids . to_a , \"similar.fields\" => similar_fields . to_a } method_url = \"/v1/environments/%s/notices\" % [ ERB :: Util . url_encode ( environment_id ) ] response = request ( method : \"GET\" , url : method_url , headers : headers , params : params , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Events and feedback [CODESPLIT] def create_event ( type : , data : ) raise ArgumentError . new ( \"type must be provided\" ) if type . nil? raise ArgumentError . new ( \"data must be provided\" ) if data . nil? headers = { } sdk_headers = Common . new . get_sdk_headers ( \"discovery\" , \"V1\" , \"create_event\" ) headers . merge! ( sdk_headers ) params = { \"version\" => @version } data = { \"type\" => type , \"data\" => data } method_url = \"/v1/events\" response = request ( method : \"POST\" , url : method_url , headers : headers , params : params , json : data , accept_json : true ) response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pad a string out to n characters with zeros [CODESPLIT] def zero_pad ( n , message ) len = message . bytesize if len == n message elsif len > n raise LengthError , \"String too long for zero-padding to #{n} bytes\" else message + zeros ( n - len ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check the length of the passed in string [CODESPLIT] def check_length ( string , length , description ) if string . nil? # code below is runs only in test cases # nil can't be converted to str with #to_str method raise LengthError , \"#{description} was nil (Expected #{length.to_int})\" , caller end if string . bytesize != length . to_int raise LengthError , \"#{description} was #{string.bytesize} bytes (Expected #{length.to_int})\" , caller end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check a passed in string converting the argument if necessary [CODESPLIT] def check_string ( string , length , description ) check_string_validation ( string ) string = string . to_s check_length ( string , length , description ) string end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check a passed in string convertion if necessary [CODESPLIT] def check_hmac_key ( string , _description ) check_string_validation ( string ) string = string . to_str if string . bytesize . zero? raise LengthError , \"#{Description} was #{string.bytesize} bytes (Expected more than 0)\" , caller end string end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check a passed string is it valid [CODESPLIT] def check_string_validation ( string ) raise TypeError , \"can't convert #{string.class} into String with #to_str\" unless string . respond_to? :to_str string = string . to_str raise EncodingError , \"strings must use BINARY encoding (got #{string.encoding})\" if string . encoding != Encoding :: BINARY end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 64 byte strings in constant time [CODESPLIT] def verify64 ( one , two ) return false unless two . bytesize == 64 && one . bytesize == 64 c_verify64 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 64 byte strings in constant time [CODESPLIT] def verify64! ( one , two ) check_length ( one , 64 , \"First message\" ) check_length ( two , 64 , \"Second message\" ) c_verify64 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 32 byte strings in constant time [CODESPLIT] def verify32 ( one , two ) return false unless two . bytesize == 32 && one . bytesize == 32 c_verify32 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 32 byte strings in constant time [CODESPLIT] def verify32! ( one , two ) check_length ( one , 32 , \"First message\" ) check_length ( two , 32 , \"Second message\" ) c_verify32 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 16 byte strings in constant time [CODESPLIT] def verify16 ( one , two ) return false unless two . bytesize == 16 && one . bytesize == 16 c_verify16 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compare two 16 byte strings in constant time [CODESPLIT] def verify16! ( one , two ) check_length ( one , 16 , \"First message\" ) check_length ( two , 16 , \"Second message\" ) c_verify16 ( one , two ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compute authenticator for message [CODESPLIT] def auth ( message ) authenticator = Util . zeros ( tag_bytes ) message = message . to_str compute_authenticator ( authenticator , message ) authenticator end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Verifies the given authenticator with the message . [CODESPLIT] def verify ( authenticator , message ) auth = authenticator . to_s Util . check_length ( auth , tag_bytes , \"Provided authenticator\" ) verify_message ( auth , message ) || raise ( BadAuthenticatorError , \"Invalid authenticator provided, message is corrupt\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Encrypts the message with a random nonce [CODESPLIT] def box ( message ) nonce = generate_nonce cipher_text = @box . box ( nonce , message ) nonce + cipher_text end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decrypts the ciphertext with a random nonce [CODESPLIT] def open ( enciphered_message ) nonce , ciphertext = extract_nonce ( enciphered_message . to_s ) @box . open ( nonce , ciphertext ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "After a fork the appender thread is not running start it if it is not running . [CODESPLIT] def reopen each do | appender | begin next unless appender . respond_to? ( :reopen ) logger . trace \"Reopening appender: #{appender.name}\" appender . reopen rescue Exception => exc logger . error \"Failed to re-open appender: #{appender.inspect}\" , exc end end logger . trace 'All appenders re-opened' end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Backward compatibility [CODESPLIT] def convert_old_appender_args ( appender , level ) options = { } options [ :level ] = level if level if appender . is_a? ( String ) options [ :file_name ] = appender elsif appender . is_a? ( IO ) options [ :io ] = appender elsif appender . is_a? ( Symbol ) || appender . is_a? ( Subscriber ) options [ :appender ] = appender else options [ :logger ] = appender end warn \"[DEPRECATED] SemanticLogger.add_appender parameters have changed. Please use: #{options.inspect}\" options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Give each appender its own logger for logging . For example trace messages sent to services or errors when something fails . [CODESPLIT] def logger @logger ||= begin logger = SemanticLogger :: Processor . logger . clone logger . name = self . class . name logger end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Dynamically supply the log level with every measurement call [CODESPLIT] def measure ( level , message , params = { } , & block ) index = Levels . index ( level ) if level_index <= index measure_internal ( level , index , message , params , block ) elsif block yield ( params ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Log a thread backtrace [CODESPLIT] def backtrace ( thread : Thread . current , level : :warn , message : 'Backtrace:' , payload : nil , metric : nil , metric_amount : nil ) log = Log . new ( name , level ) return false unless meets_log_level? ( log ) backtrace = if thread == Thread . current Utils . extract_backtrace else log . thread_name = thread . name log . tags = ( thread [ :semantic_logger_tags ] || [ ] ) . clone log . named_tags = ( thread [ :semantic_logger_named_tags ] || { } ) . clone thread . backtrace end # TODO: Keep backtrace instead of transforming into a text message at this point # Maybe log_backtrace: true if backtrace message += \"\\n\" message << backtrace . join ( \"\\n\" ) end if log . assign ( message : message , backtrace : backtrace , payload : payload , metric : metric , metric_amount : metric_amount ) && ! filtered? ( log ) self . log ( log ) else false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add the tags or named tags to the list of tags to log for this thread whilst the supplied block is active . [CODESPLIT] def tagged ( * tags , & block ) # Allow named tags to be passed into the logger if tags . size == 1 tag = tags [ 0 ] return yield if tag . nil? || tag == '' return tag . is_a? ( Hash ) ? SemanticLogger . named_tagged ( tag , block ) : SemanticLogger . fast_tag ( tag . to_s , block ) end # Need to flatten and reject empties to support calls from Rails 4 new_tags = tags . flatten . collect ( :to_s ) . reject ( :empty? ) SemanticLogger . tagged ( new_tags , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the list of tags pushed after flattening them out and removing blanks [CODESPLIT] def push_tags ( * tags ) # Need to flatten and reject empties to support calls from Rails 4 new_tags = tags . flatten . collect ( :to_s ) . reject ( :empty? ) SemanticLogger . push_tags ( new_tags ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Whether to log the supplied message based on the current filter if any [CODESPLIT] def filtered? ( log ) return false if @filter . nil? @filter . is_a? ( Regexp ) ? ( @filter =~ log . name ) . nil? : @filter . call ( log ) != true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Log message at the specified level [CODESPLIT] def log_internal ( level , index , message = nil , payload = nil , exception = nil , & block ) log = Log . new ( name , level , index ) should_log = if payload . nil? && exception . nil? && message . is_a? ( Hash ) # Check if someone just logged a hash payload instead of meaning to call semantic logger if message . key? ( :message ) || message . key? ( :payload ) || message . key? ( :exception ) || message . key? ( :metric ) log . assign ( message ) else log . assign_positional ( nil , message , nil , block ) end else log . assign_positional ( message , payload , exception , block ) end # Log level may change during assign due to :on_exception_level self . log ( log ) if should_log && should_log? ( log ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Measure the supplied block and log the message [CODESPLIT] def measure_internal ( level , index , message , params ) exception = nil result = nil # Single parameter is a hash if params . empty? && message . is_a? ( Hash ) params = message message = nil end start = Process . clock_gettime ( Process :: CLOCK_MONOTONIC ) begin if block_given? result = if ( silence_level = params [ :silence ] ) # In case someone accidentally sets `silence: true` instead of `silence: :error` silence_level = :error if silence_level == true silence ( silence_level ) { yield ( params ) } else yield ( params ) end end rescue Exception => exc exception = exc ensure # Must use ensure block otherwise a `return` in the yield above will skip the log entry log = Log . new ( name , level , index ) exception ||= params [ :exception ] message = params [ :message ] if params [ :message ] duration = if block_given? 1_000.0 * ( Process . clock_gettime ( Process :: CLOCK_MONOTONIC ) - start ) else params [ :duration ] || raise ( 'Mandatory block missing when :duration option is not supplied' ) end # Extract options after block completes so that block can modify any of the options payload = params [ :payload ] # May return false due to elastic logging should_log = log . assign ( message : message , payload : payload , min_duration : params [ :min_duration ] || 0.0 , exception : exception , metric : params [ :metric ] , metric_amount : params [ :metric_amount ] , duration : duration , log_exception : params [ :log_exception ] || :partial , on_exception_level : params [ :on_exception_level ] ) # Log level may change during assign due to :on_exception_level self . log ( log ) if should_log && should_log? ( log ) raise exception if exception result end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "For measuring methods and logging their duration . [CODESPLIT] def measure_method ( index : , level : , message : , min_duration : , metric : , log_exception : , on_exception_level : ) # Ignores filter, silence, payload exception = nil start = Process . clock_gettime ( Process :: CLOCK_MONOTONIC ) begin yield rescue Exception => exc exception = exc ensure log = Log . new ( name , level , index ) # May return false due to elastic logging should_log = log . assign ( message : message , min_duration : min_duration , exception : exception , metric : metric , duration : 1_000.0 * ( Process . clock_gettime ( Process :: CLOCK_MONOTONIC ) - start ) , log_exception : log_exception , on_exception_level : on_exception_level ) # Log level may change during assign due to :on_exception_level log ( log ) if should_log && should_log? ( log ) raise exception if exception end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a Logger instance [CODESPLIT] def log ( log , message = nil , progname = nil , & block ) # Compatibility with ::Logger return add ( log , message , progname , block ) unless log . is_a? ( SemanticLogger :: Log ) Logger . call_subscribers ( log ) Logger . processor . log ( log ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assign named arguments to this log entry supplying defaults where applicable [CODESPLIT] def assign ( message : nil , payload : nil , min_duration : 0.0 , exception : nil , metric : nil , metric_amount : nil , duration : nil , backtrace : nil , log_exception : :full , on_exception_level : nil , dimensions : nil ) # Elastic logging: Log when :duration exceeds :min_duration # Except if there is an exception when it will always be logged if duration self . duration = duration return false if ( duration < min_duration ) && exception . nil? end self . message = message if payload && payload . is_a? ( Hash ) self . payload = payload elsif payload self . message = message . nil? ? payload . to_s : \"#{message} -- #{payload}\" self . payload = nil end if exception case log_exception when :full self . exception = exception when :partial self . message = \"#{message} -- Exception: #{exception.class}: #{exception.message}\" when nil , :none # Log the message without the exception that was raised nil else raise ( ArgumentError , \"Invalid value:#{log_exception.inspect} for argument :log_exception\" ) end # On exception change the log level if on_exception_level self . level = on_exception_level self . level_index = Levels . index ( level ) end end if backtrace self . backtrace = Utils . extract_backtrace ( backtrace ) elsif level_index >= SemanticLogger . backtrace_level_index self . backtrace = Utils . extract_backtrace end if metric self . metric = metric self . metric_amount = metric_amount self . dimensions = dimensions end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assign positional arguments to this log entry supplying defaults where applicable [CODESPLIT] def assign_positional ( message = nil , payload = nil , exception = nil ) # Exception being logged? # Under JRuby a java exception is not a Ruby Exception #   Java::JavaLang::ClassCastException.new.is_a?(Exception) => false if exception . nil? && payload . nil? && message . respond_to? ( :backtrace ) && message . respond_to? ( :message ) exception = message message = nil elsif exception . nil? && payload && payload . respond_to? ( :backtrace ) && payload . respond_to? ( :message ) exception = payload payload = nil elsif payload && ! payload . is_a? ( Hash ) message = message . nil? ? payload : \"#{message} -- #{payload}\" payload = nil end # Add result of block as message or payload if not nil if block_given? && ( result = yield ) if result . is_a? ( String ) message = message . nil? ? result : \"#{message} -- #{result}\" assign ( message : message , payload : payload , exception : exception ) elsif message . nil? && result . is_a? ( Hash ) && %i[ message payload exception ] . any? { | k | result . key? k } assign ( result ) elsif payload &. respond_to? ( :merge ) assign ( message : message , payload : payload . merge ( result ) , exception : exception ) else assign ( message : message , payload : result , exception : exception ) end else assign ( message : message , payload : payload , exception : exception ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Call the block for exception and any nested exception [CODESPLIT] def each_exception # With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81 depth = 0 exceptions = [ ] ex = exception while ! ex . nil? && ! exceptions . include? ( ex ) && exceptions . length < MAX_EXCEPTIONS_TO_UNWRAP exceptions << ex yield ( ex , depth ) depth += 1 ex = if ex . respond_to? ( :cause ) && ex . cause ex . cause elsif ex . respond_to? ( :continued_exception ) && ex . continued_exception ex . continued_exception elsif ex . respond_to? ( :original_exception ) && ex . original_exception ex . original_exception end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns [ String ] the exception backtrace including all of the child / caused by exceptions [CODESPLIT] def backtrace_to_s trace = '' each_exception do | exception , i | if i . zero? trace = ( exception . backtrace || [ ] ) . join ( \"\\n\" ) else trace << \"\\nCause: #{exception.class.name}: #{exception.message}\\n#{(exception.backtrace || []).join(\"\\n\")}\" end end trace end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns [ String ] the duration in human readable form [CODESPLIT] def duration_human return nil unless duration seconds = duration / 1000 if seconds >= 86_400.0 # 1 day \"#{(seconds / 86_400).to_i}d #{Time.at(seconds).strftime('%-Hh %-Mm')}\" elsif seconds >= 3600.0 # 1 hour Time . at ( seconds ) . strftime ( '%-Hh %-Mm' ) elsif seconds >= 60.0 # 1 minute Time . at ( seconds ) . strftime ( '%-Mm %-Ss' ) elsif seconds >= 1.0 # 1 second \"#{format('%.3f', seconds)}s\" else duration_to_s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extract the filename and line number from the last entry in the supplied backtrace [CODESPLIT] def extract_file_and_line ( stack , short_name = false ) match = CALLER_REGEXP . match ( stack . first ) [ short_name ? File . basename ( match [ 1 ] ) : match [ 1 ] , match [ 2 ] . to_i ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns [ String String ] the file_name and line_number from the backtrace supplied in either the backtrace or exception [CODESPLIT] def file_name_and_line ( short_name = false ) stack = backtrace || exception &. backtrace extract_file_and_line ( stack , short_name ) if stack &. size &. positive? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "DEPRECATED : Use SemanticLogger :: Formatters :: Raw [CODESPLIT] def to_h ( host = SemanticLogger . host , application = SemanticLogger . application ) logger = DeprecatedLogger . new ( host , application ) SemanticLogger :: Formatters :: Raw . new . call ( self , logger ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a human readable string that contains + corrections + . This formatter is designed to be less verbose to not take too much screen space while being helpful enough to the user . [CODESPLIT] def message_for ( corrections ) return \"\" if corrections . empty? output = \"\\n\\n    Did you mean? \" . dup output << corrections . join ( \"\\n                  \" ) output << \"\\n \" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : This code is based directly on the Text gem implementation Copyright ( c ) 2006 - 2013 Paul Battley Michael Neumann Tim Fletcher . [CODESPLIT] def distance ( str1 , str2 ) n = str1 . length m = str2 . length return m if n . zero? return n if m . zero? d = ( 0 .. m ) . to_a x = nil # to avoid duplicating an enumerable object, create it outside of the loop str2_codepoints = str2 . codepoints str1 . each_codepoint . with_index ( 1 ) do | char1 , i | j = 0 while j < m cost = ( char1 == str2_codepoints [ j ] ) ? 0 : 1 x = min3 ( d [ j + 1 ] + 1 , # insertion i + 1 , # deletion d [ j ] + cost # substitution ) d [ j ] = i i = x j += 1 end d [ m ] = x end x end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "detects the minimum value out of three arguments . This method is faster than [ a b c ] . min and puts less GC pressure . See https : // github . com / yuki24 / did_you_mean / pull / 1 for a performance benchmark . [CODESPLIT] def min3 ( a , b , c ) if a < b && a < c a elsif b < c b else c end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Used by flor when it looks up for a variable and finds nothing . The last step is to ask the ganger if it knows about a tasker under the given ( domain and ) name . [CODESPLIT] def has_tasker? ( exid , name ) #return false if RESERVED_NAMES.include?(name) d = Flor . domain ( exid ) ! ! ( @unit . loader . tasker ( d , 'ganger' ) || @unit . loader . tasker ( d , 'tasker' ) || @unit . loader . tasker ( d , name ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called by Flor :: Scheduler . The ganger then has to hand the task ( the message ) to the proper tasker . [CODESPLIT] def task ( executor , message ) domain = message [ 'exid' ] . split ( '-' , 2 ) . first tname = message [ 'tasker' ] tconf = ( ! message [ 'routed' ] && ( @unit . loader . tasker ( domain , 'ganger' , message ) || @unit . loader . tasker ( domain , 'tasker' , message ) ) ) || @unit . loader . tasker ( domain , tname , message ) fail ArgumentError . new ( \"tasker #{tname.inspect} not found\" ) unless tconf if tconf . is_a? ( Array ) points = [ nil , message [ 'point' ] ] points << 'detask' if points . include? ( 'cancel' ) tconf = tconf . find { | h | points . include? ( h [ 'point' ] ) } end message [ 'tconf' ] = tconf unless tconf [ 'include_tconf' ] == false message [ 'vars' ] = gather_vars ( executor , tconf , message ) m = dup_message ( message ) # # the tasker gets a copy of the message (and it can play with it # to its heart content), meanwhile the message is handed to the # \"post\" notifiers. @unit . caller . call ( self , tconf , m ) # # might return a re-routing message, # especially if it's a domain tasker end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "By default taskers don t see the flor variables in the execution . If include_vars or exclude_vars is present in the configuration of the tasker some or all of the variables are passed . [CODESPLIT] def gather_vars ( executor , tconf , message ) # try to return before a potentially costly call to executor.vars(nid) return nil if ( tconf . keys & %w[ include_vars exclude_vars ] ) . empty? # default behaviour, don't pass variables to taskers iv = expand_filter ( tconf [ 'include_vars' ] ) return nil if iv == false ev = expand_filter ( tconf [ 'exclude_vars' ] ) return { } if ev == true vars = executor . vars ( message [ 'nid' ] ) return vars if iv == true vars = vars . select { | k , v | var_match ( k , iv ) } if iv vars = vars . reject { | k , v | var_match ( k , ev ) } if ev vars end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "NB : logger configuration entries start with hok_ [CODESPLIT] def shutdown @hooks . each do | n , o , hook , b | hook . shutdown if hook . respond_to? ( :shutdown ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Dumps all or some of the executions to a JSON string . See Scheduler#load for importing . [CODESPLIT] def dump ( io = nil , opts = nil , & block ) io , opts = nil , io if io . is_a? ( Hash ) opts ||= { } o = lambda { | k | v = opts [ k ] || opts [ \"#{k}s\" . to_sym ] ; v ? Array ( v ) : nil } # exis = o [ :exid ] doms = o [ :domain ] sdms = o [ :strict_domain ] || o [ :sdomain ] # filter = lambda { | q | q = q . where ( exid : exis ) if exis q = q . where { Sequel . | ( doms . inject ( [ ] ) { | a , d | a . concat ( [ { domain : d } , Sequel . like ( :domain , d + '.%' ) ] ) } ) } if doms q = q . where ( domain : sdms ) if sdms q } exs , tms , tps , pts = storage . db . transaction { [ filter [ executions ] . collect ( :to_h ) , filter [ timers ] . collect ( :to_h ) , filter [ traps ] . collect ( :to_h ) , filter [ pointers ] . collect ( :to_h ) ] } o = io ? io : StringIO . new h = { timestamp : Flor . tstamp , executions : exs , timers : tms , traps : tps , pointers : pts } block . call ( h ) if block JSON . dump ( h , o ) io ? io : o . string end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read a previous JSON dump and loads it into the storage . Can be useful when testing dumping once and reloading multiple times to test variants . [CODESPLIT] def load ( string_or_io , opts = { } , & block ) s = string_or_io s = s . read if s . respond_to? ( :read ) string_or_io . close if string_or_io . respond_to? ( :close ) && opts [ :close ] h = JSON . load ( s ) mks = DUMP_KEYS - h . keys fail Flor :: FlorError . new ( \"missing keys #{mks.inspect}\" ) if mks . any? o = lambda { | k | v = opts [ k ] || opts [ \"#{k}s\" . to_sym ] ; v ? Array ( v ) : nil } # exis = o [ :exid ] doms = o [ :domain ] sdms = o [ :strict_domain ] || o [ :sdomain ] # doms = doms . collect { | d | / \\A #{ d } \\. #{ Flor :: NAME_REX } \\z / } if doms counts = { executions : 0 , timers : 0 , traps : 0 , pointers : 0 , total : 0 } storage . db . transaction do ( DUMP_KEYS - %w[ timestamp ] ) . each do | k | y = k . to_sym cla = storage . send ( k ) cols = cla . columns rows = h [ k ] . inject ( [ ] ) { | a , hh | next a if exis && ! exis . include? ( hh [ 'exid' ] ) next a if doms && ! doms . find { | d | d . match ( hh [ 'domain' ] ) } next a if sdms && ! sdms . include? ( hh [ 'domain' ] ) counts [ y ] += 1 counts [ :total ] += 1 vals = cla . from_h ( hh ) a << cols . collect { | c | vals [ c ] } } cla . import ( cols , rows ) if rows . any? end block . call ( h ) if block end counts end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def procedures ( path ) [CODESPLIT] def library ( domain , name = nil , opts = { } ) path , key = split ( domain , name ) libs = entries ( 'libraries' , path ) if opts [ :subflows ] # used by \"graft\"/\"import\" libs += entries ( 'sublibraries' , path ) libs = libs . sort_by { | pa , _ , _ | pa . count ( '.' ) } end libs . each { | pa , ke , va | next unless ke == key return [ [ pa , ke ] . join ( '.' ) , va ] } nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "point for messages that after consumption are conserved in the execution s closing_messages array [CODESPLIT] def do_run @unit . logger . log_run_start ( self ) counter_next ( 'runs' ) t0 = Time . now ( @unit . conf [ 'exe_max_messages' ] || 77 ) . times do | i | break if @shutdown m = @messages . shift break unless m m = ( @messages << m ) . shift if m [ 'point' ] == 'terminated' && @messages . any? # # handle 'terminated' messages last ms = process ( m ) @consumed << m ims , oms = ms . partition { | mm | mm [ 'exid' ] == @exid } # qui est \"in\", qui est \"out\"? counter_add ( 'omsgs' , oms . size ) # keep track of \"out\" messages, messages to other executions @messages . concat ( ims ) @unit . storage . put_messages ( oms ) end @alive = false @execution . merge! ( closing_messages : @consumed . select { | m | CLOSING_POINTS . include? ( m [ 'point' ] ) } ) @unit . storage . put_execution ( @execution ) @unit . storage . consume ( @consumed ) @unit . storage . put_messages ( @messages ) du = Time . now - t0 t0 = Flor . tstamp ( t0 ) @unit . logger . log_run_end ( self , t0 , du ) @unit . hooker . notify ( self , make_end_message ( t0 , du , @execution [ 'size' ] ) ) @consumed . clear rescue Exception => exc # TODO eventually, have a dump dir fn = [ 'flor' , @unit . conf [ 'env' ] , @unit . identifier , @exid , 'r' + counter ( 'runs' ) . to_s ] . collect ( :to_s ) . join ( '_' ) + '.dump' @unit . logger . error ( \"#{self.class}#do_run()\" , exc , \"(dumping to #{fn})\" ) File . open ( fn , 'wb' ) do | f | f . puts ( Flor . to_pretty_s ( { execution : @execution , messages : @messages , consumed : @consumed , traps : @traps . collect ( :to_h ) , exid : @exid , alive : @alive , shutdown : @shutdown , thread : [ @thread . object_id , @thread . to_s ] } ) ) f . puts ( '-' * 80 ) f . puts ( on_do_run_exc ( exc ) ) end #puts on_do_run_exc(exc) # dump notification above end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "For domain taskers [CODESPLIT] def route ( name ) if name . is_a? ( String ) [ Flor . dup_and_merge ( @message , 'tasker' => name , 'original_tasker' => @message [ 'tasker' ] , 'routed' => true ) ] else [ Flor . dup_and_merge ( @message , 'routed' => ! ! name ) ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "So that #reply may be called with reply reply ( [CODESPLIT] def derive_message ( m ) exid = m [ 'exid' ] nid = m [ 'nid' ] pl = m [ 'payload' ] return m if Flor . is_exid? ( exid ) && Flor . is_nid? ( nid ) && pl . is_a? ( Hash ) m = Flor . to_string_keyed_hash ( m ) h = Flor . dup ( @message ) ks = m . keys if ks == [ 'payload' ] h [ 'payload' ] = m [ 'payload' ] elsif ( ks & %w[ ret set unset ] ) . size > 0 pl = ( h [ 'payload' ] ||= { } ) pl [ 'ret' ] = m [ 'ret' ] if m . has_key? ( 'ret' ) ( m [ 'set' ] || { } ) . each { | k , v | pl [ k ] = v } ( m [ 'unset' ] || [ ] ) . each { | k | pl . delete ( k . to_s ) } else h [ 'payload' ] = m end h end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Avoid the proc / cancel problem upstreams in ConfExecutor by ignoring non - core procedures keeping this around for now [CODESPLIT] def extract_filters ( h ) r = { } r [ :consumed ] = h [ 'consumed' ] r [ :point ] = Flor . h_fetch_a ( h , 'points' , 'point' , nil ) r [ :nid ] = Flor . h_fetch_a ( h , 'nids' , 'nid' , nil ) r [ :heap ] = Flor . h_fetch_a ( h , 'heaps' , 'heap' , nil ) r [ :heat ] = Flor . h_fetch_a ( h , 'heats' , 'heat' , nil ) #opts[:name] = data['names'] r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TODO eventually merge with Waiter . parse_serie [CODESPLIT] def message_match? ( msg_s , ountil ) return false unless ountil ms = msg_s ; ms = [ ms ] if ms . is_a? ( Hash ) nid , point = ountil . split ( ' ' ) ms . find { | m | m [ 'nid' ] == nid && m [ 'point' ] == point } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def procedures ( path ) [CODESPLIT] def library ( domain , name = nil , opts = { } ) domain , name , opts = [ domain , nil , name ] if name . is_a? ( Hash ) domain , name = split_dn ( domain , name ) if m = name . match ( / \\. \\z / ) name = name [ 0 .. m [ 1 ] . length - 1 ] end path , _ , _ = ( Dir [ File . join ( @root , '**/*.{flo,flor}' ) ] ) . select { | f | f . index ( '/lib/' ) } . collect { | pa | [ pa , expose_dn ( pa , opts ) ] } . select { | pa , d , n | n == name && Flor . sub_domain? ( d , domain ) } . sort_by { | pa , d , n | d . count ( '.' ) } . last path ? [ Flor . relativize_path ( path ) , File . read ( path ) ] : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create_table : flor_timers do [CODESPLIT] def to_trigger_message d = self . data ( false ) m = d [ 'message' ] m [ 'timer_id' ] = self . id sm = d [ 'm' ] { 'point' => 'trigger' , 'exid' => self . exid , 'nid' => self . onid , 'bnid' => self . nid , 'type' => self . type , 'schedule' => self . schedule , 'timer_id' => self . id , 'message' => m , 'sm' => sm } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "tasker not task since task is already a message point [CODESPLIT] def row_waiter? @serie . find { | _ , points | points . find { | po | pos = po . split ( ':' ) pos . length > 1 && ROW_PSEUDO_POINTS . include? ( pos [ 0 ] ) } } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete tables in the storage database that begin with flor_ and have more than 2 columns ( the Sequel schema_info table has 1 column as of this writing ) [CODESPLIT] def delete_tables @db . tables . each { | t | @db [ t ] . delete if t . to_s . match ( / / ) && @db [ t ] . columns . size > 2 } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a Flor :: Execution instance linked to this model [CODESPLIT] def execution ( reload = false ) exid = @values [ :exid ] ; return nil unless exid @flor_model_cache_execution = nil if reload @flor_model_cache_execution ||= unit . executions [ exid : exid ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the node hash linked to this model [CODESPLIT] def node ( reload = false ) nid = @values [ :nid ] ; return nil unless nid exe = execution ( reload ) ; return nil unless exe nodes = exe . data [ 'nodes' ] ; return nil unless nodes nodes [ nid ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a nid returns a copy of all the var the node sees at that point . [CODESPLIT] def vars ( nid , vs = { } ) n = node ( nid ) ; return vs unless n ( n [ 'vars' ] || { } ) . each { | k , v | vs [ k ] = Flor . dup ( v ) unless vs . has_key? ( k ) } pnid = n [ 'parent' ] if @unit . loader && pnid == nil && n [ 'vdomain' ] != false @unit . loader . variables ( n [ 'vdomain' ] || Flor . domain ( @exid ) ) . each { | k , v | vs [ k ] = Flor . dup ( v ) unless vs . has_key? ( k ) } end if cn = n [ 'cnid' ] ; vars ( cn , vs ) ; end vars ( pnid , vs ) if pnid vs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This saves the modified trees in the parent when the node is removed it works ok except for 3 ( 2017 - 05 - 9 ) failing specs . [CODESPLIT] def leave_tags ( message , node ) ts = node [ 'tags' ] ; return [ ] unless ts && ts . any? [ { 'point' => 'left' , 'tags' => ts , 'exid' => exid , 'nid' => node [ 'nid' ] , 'payload' => message [ 'payload' ] } ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return an empty array of new messages . No direct effect . [CODESPLIT] def lookup_on_error_parent ( message ) nd = Flor :: Node . new ( self , nil , message ) . on_error_parent nd ? nd . to_procedure_node : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create_table : flor_traps do [CODESPLIT] def to_hook opts = { } opts [ :consumed ] = tconsumed opts [ :point ] = tpoints . split ( ',' ) if tpoints opts [ :tag ] = do_split ( ttags ) if ttags opts [ :heap ] = do_split ( theaps ) if theaps opts [ :heat ] = do_split ( theats ) if theats opts [ :name ] = data [ 'names' ] case trange when 'execution' opts [ :exid ] = exid when 'subdomain' opts [ :subdomain ] = Flor . domain ( exid ) when 'domain' opts [ :domain ] = Flor . domain ( exid ) else #'subnid' # default opts [ :exid ] = exid opts [ :subnid ] = true end [ \"trap#{id}\" , opts , self , nil ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns true if the trap should be removed from the execution s list of traps [CODESPLIT] def decrement c = data [ 'count' ] return false unless c c = c - 1 data [ 'count' ] = c self [ :status ] = s = ( c > 0 ) ? 'active' : 'consumed' self . update ( content : Flor :: Storage . to_blob ( @flor_model_cache_data ) , status : s ) c < 1 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Mixlib :: CLI class . If you override this make sure you call super! [CODESPLIT] def parse_options ( argv = ARGV ) argv = argv . dup opt_parser . parse! ( argv ) # Deal with any required values options . each do | opt_key , opt_value | if opt_value [ :required ] && ! config . key? ( opt_key ) reqarg = opt_value [ :short ] || opt_value [ :long ] puts \"You must supply #{reqarg}!\" puts @opt_parser exit 2 end if opt_value [ :in ] unless opt_value [ :in ] . kind_of? ( Array ) raise ( ArgumentError , \"Options config key :in must receive an Array\" ) end if config [ opt_key ] && ! opt_value [ :in ] . include? ( config [ opt_key ] ) reqarg = opt_value [ :short ] || opt_value [ :long ] puts \"#{reqarg}: #{config[opt_key]} is not included in the list ['#{opt_value[:in].join(\"', '\")}'] \" puts @opt_parser exit 2 end end end @cli_arguments = argv argv end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The option parser generated from the mixlib - cli DSL . + opt_parser + can be used to print a help message including the banner and any CLI options via puts opt_parser . === Returns opt_parser<OptionParser > :: The option parser object . [CODESPLIT] def opt_parser @opt_parser ||= OptionParser . new do | opts | # Set the banner opts . banner = banner # Create new options options . sort { | a , b | a [ 0 ] . to_s <=> b [ 0 ] . to_s } . each do | opt_key , opt_val | opt_args = build_option_arguments ( opt_val ) opt_method = case opt_val [ :on ] when :on :on when :tail :on_tail when :head :on_head else raise ArgumentError , \"You must pass :on, :tail, or :head to :on\" end parse_block = Proc . new ( ) do | c | config [ opt_key ] = if opt_val [ :proc ] if opt_val [ :proc ] . arity == 2 # New hotness to allow for reducer-style procs. opt_val [ :proc ] . call ( c , config [ opt_key ] ) else # Older single-argument proc. opt_val [ :proc ] . call ( c ) end else # No proc. c end puts opts if opt_val [ :show_options ] exit opt_val [ :exit ] if opt_val [ :exit ] end full_opt = [ opt_method ] opt_args . inject ( full_opt ) { | memo , arg | memo << arg ; memo } full_opt << parse_block opts . send ( full_opt ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calls Worker#work but after the current process is forked . The parent process will wait on the child process to exit . [CODESPLIT] def fork_and_work cpid = fork { setup_child ; work } log ( :at => :fork , :pid => cpid ) Process . wait ( cpid ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Blocks on locking a job and once a job is locked it will process the job . [CODESPLIT] def work queue , job = lock_job if queue && job QC . log_yield ( :at => \"work\" , :job => job [ :id ] ) do process ( queue , job ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Attempt to lock a job in the queue s table . If a job can be locked this method returns an array with 2 elements . The first element is the queue from which the job was locked and the second is a hash representation of the job . If a job is returned its locked_at column has been set in the job s row . It is the caller s responsibility to delete the job row from the table when the job is complete . [CODESPLIT] def lock_job log ( :at => \"lock_job\" ) job = nil while @running @queues . each do | queue | if job = queue . lock return [ queue , job ] end end @conn_adapter . wait ( @wait_interval , @queues . map { | q | q . name } ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A job is processed by evaluating the target code . if the job is evaluated with no exceptions then it is deleted from the queue . If the job has raised an exception the responsibility of what to do with the job is delegated to Worker#handle_failure . If the job is not finished and an INT signal is trapped this method will unlock the job in the queue . [CODESPLIT] def process ( queue , job ) start = Time . now finished = false begin call ( job ) . tap do queue . delete ( job [ :id ] ) finished = true end rescue => e handle_failure ( job , e ) finished = true ensure if ! finished queue . unlock ( job [ :id ] ) end ttp = Integer ( ( Time . now - start ) * 1000 ) QC . measure ( \"time-to-process=#{ttp} source=#{queue.name}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Each job includes a method column . We will use ruby s eval to grab the ruby object from memory . We send the method to the object and pass the args . [CODESPLIT] def call ( job ) args = job [ :args ] receiver_str , _ , message = job [ :method ] . rpartition ( '.' ) receiver = eval ( receiver_str ) receiver . send ( message , args ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "enqueue ( m a ) inserts a row into the jobs table and trigger a notification . The job s queue is represented by a name column in the row . There is a trigger on the table which will send a NOTIFY event on a channel which corresponds to the name of the queue . The method argument is a string encoded ruby expression . The expression will be separated by a . character and then eval d . Examples of the method argument include : puts Kernel . puts MyObject . new . puts . The args argument will be encoded as JSON and stored as a JSON datatype in the row . ( If the version of PG does not support JSON then the args will be stored as text . The args are stored as a collection and then splatted inside the worker . Examples of args include : hello world [ hello world ] hello world . This method returns a hash with the id of the enqueued job . [CODESPLIT] def enqueue ( method , * args ) QC . log_yield ( :measure => 'queue.enqueue' ) do s = \"INSERT INTO #{QC.table_name} (q_name, method, args) VALUES ($1, $2, $3) RETURNING id\" conn_adapter . execute ( s , name , method , JSON . dump ( args ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "enqueue_at ( t m a ) inserts a row into the jobs table representing a job to be executed not before the specified time . The time argument must be a Time object or a float timestamp . The method and args argument must be in the form described in the documentation for the #enqueue method . This method returns a hash with the id of the enqueued job . [CODESPLIT] def enqueue_at ( timestamp , method , * args ) offset = Time . at ( timestamp ) . to_i - Time . now . to_i enqueue_in ( offset , method , args ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "enqueue_in ( t m a ) inserts a row into the jobs table representing a job to be executed not before the specified time offset . The seconds argument must be an integer . The method and args argument must be in the form described in the documentation for the #enqueue method . This method returns a hash with the id of the enqueued job . [CODESPLIT] def enqueue_in ( seconds , method , * args ) QC . log_yield ( :measure => 'queue.enqueue' ) do s = \"INSERT INTO #{QC.table_name} (q_name, method, args, scheduled_at)\n             VALUES ($1, $2, $3, now() + interval '#{seconds.to_i} seconds')\n             RETURNING id\" conn_adapter . execute ( s , name , method , JSON . dump ( args ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Net :: HTTP [CODESPLIT] def session @session ||= begin http = Net :: HTTP . new @host , @port http . use_ssl = self . use_ssl http . verify_mode = self . verify_mode http . read_timeout = self . read_timeout http . ssl_version = self . ssl_version if self . use_ssl http . start end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "title : legend : xAxis : yAxis : tooltip : credits : : plotOptions [CODESPLIT] def defaults_options self . title ( { :text => nil } ) self . legend ( { :layout => \"vertical\" , :style => { } } ) self . xAxis ( { } ) self . yAxis ( { :title => { :text => nil } , :labels => { } } ) self . tooltip ( { :enabled => true } ) self . credits ( { :enabled => false } ) self . plotOptions ( { :areaspline => { } } ) self . chart ( { :defaultSeriesType => \"line\" , :renderTo => nil } ) self . subtitle ( { } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pass other methods through to the javascript high_chart object . [CODESPLIT] def method_missing ( meth , opts = { } ) if meth . to_s == 'to_ary' super end if meth . to_s . end_with? '!' deep_merge_options meth [ 0 .. - 2 ] . to_sym , opts else merge_options meth , opts end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a simple series to the graph : [CODESPLIT] def series ( opts = { } ) if not opts . empty? @series_data << OptionsKeyFilter . filter ( opts . merge ( :name => opts [ :name ] , :data => opts [ :data ] ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def write_session ( req , sid , session_data , options ) cas_ticket = ( session_data [ 'cas' ] [ 'ticket' ] unless session_data [ 'cas' ] . nil? ) session = if ActiveRecord . respond_to? ( :version ) && ActiveRecord . version >= Gem :: Version . new ( '4.0.0' ) Session . where ( session_id : sid ) . first_or_initialize else Session . find_or_initialize_by_session_id ( sid ) end session . data = pack ( session_data ) session . cas_ticket = cas_ticket success = session . save success ? session . session_id : false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def delete_session ( req , sid , options ) Session . where ( session_id : sid ) . delete_all options [ :drop ] ? nil : generate_sid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 1 . * method [CODESPLIT] def set_session ( env , sid , session_data , options ) # rack 1.x compatibilty write_session ( Rack :: Request . new ( env ) , sid , session_data , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 1 . * method [CODESPLIT] def destroy_session ( env , sid , options ) # rack 1.x compatibilty delete_session ( Rack :: Request . new ( env ) , sid , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def find_session ( env , sid ) if sid . nil? sid = generate_sid data = nil else unless session = Session . find_by_id ( sid ) session = { } # force generation of new sid since there is no associated session sid = generate_sid end data = unpack ( session [ 'data' ] ) end [ sid , data ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def write_session ( env , sid , session_data , options ) cas_ticket = ( session_data [ 'cas' ] [ 'ticket' ] unless session_data [ 'cas' ] . nil? ) success = Session . write ( session_id : sid , data : pack ( session_data ) , cas_ticket : cas_ticket ) success ? sid : false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "params can be an array or a hash [CODESPLIT] def remove_params ( params ) self . tap do | u | u . query_values = ( u . query_values || { } ) . tap do | qv | params . each do | key , value | qv . delete key end end if u . query_values . empty? u . query_values = nil end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "initially borrowed from omniauth - cas [CODESPLIT] def parse_user_info ( node ) return nil if node . nil? { } . tap do | hash | node . children . each do | e | unless e . kind_of? ( Nokogiri :: XML :: Text ) || e . name == 'proxies' # There are no child elements if e . element_children . count == 0 if hash . has_key? ( e . name ) hash [ e . name ] = [ hash [ e . name ] ] if hash [ e . name ] . is_a? String hash [ e . name ] << e . content else hash [ e . name ] = e . content end elsif e . element_children . count # JASIG style extra attributes if e . name == 'attributes' hash . merge! ( parse_user_info ( e ) ) else hash [ e . name ] = [ ] if hash [ e . name ] . nil? hash [ e . name ] = [ hash [ e . name ] ] if hash [ e . name ] . is_a? String hash [ e . name ] . push ( parse_user_info ( e ) ) end end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def find_session ( env , sid ) if sid . nil? sid = generate_sid data = nil else unless session = Session . where ( _id : sid ) . first session = { } # force generation of new sid since there is no associated session sid = generate_sid end data = unpack ( session [ 'data' ] ) end [ sid , data ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def write_session ( env , sid , session_data , options ) cas_ticket = ( session_data [ 'cas' ] [ 'ticket' ] unless session_data [ 'cas' ] . nil? ) session = Session . find_or_initialize_by ( _id : sid ) success = session . update_attributes ( data : pack ( session_data ) , cas_ticket : cas_ticket ) success ? session . id : false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rack 2 . 0 method [CODESPLIT] def delete_session ( env , sid , options ) Session . where ( _id : sid ) . delete options [ :drop ] ? nil : generate_sid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / PerceivedComplexity [CODESPLIT] def remote_execution_proxies ( provider , authorized = true ) proxies = { } proxies [ :subnet ] = execution_interface . subnet . remote_execution_proxies . with_features ( provider ) if execution_interface && execution_interface . subnet proxies [ :fallback ] = smart_proxies . with_features ( provider ) if Setting [ :remote_execution_fallback_proxy ] if Setting [ :remote_execution_global_proxy ] proxy_scope = if Taxonomy . enabled_taxonomies . any? && User . current . present? :: SmartProxy . with_taxonomy_scope_override ( location , organization ) else :: SmartProxy . unscoped end proxy_scope = proxy_scope . authorized if authorized proxies [ :global ] = proxy_scope . with_features ( provider ) end proxies end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initiates run of the remote command and yields the data when available . The yielding doesn t happen automatically but as part of calling the refresh method . [CODESPLIT] def run_async ( command ) raise 'Async command already in progress' if @started @started = false @user_method . reset session . open_channel do | channel | channel . request_pty channel . on_data do | ch , data | publish_data ( data , 'stdout' ) unless @user_method . filter_password? ( data ) @user_method . on_data ( data , ch ) end channel . on_extended_data { | ch , type , data | publish_data ( data , 'stderr' ) } # standard exit of the command channel . on_request ( 'exit-status' ) { | ch , data | publish_exit_status ( data . read_long ) } # on signal: sending the signal value (such as 'TERM') channel . on_request ( 'exit-signal' ) do | ch , data | publish_exit_status ( data . read_string ) ch . close # wait for the channel to finish so that we know at the end # that the session is inactive ch . wait end channel . exec ( command ) do | _ , success | @started = true raise ( 'Error initializing command' ) unless success end end session . process ( 0 ) { ! run_started? } return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "when a remote server disconnects it s hard to tell if it was on purpose ( when calling reboot ) or it s an error . When it s expected we expect the script to produce restart host as its last command output [CODESPLIT] def check_expecting_disconnect last_output = @continuous_output . raw_outputs . find { | d | d [ 'output_type' ] == 'stdout' } return unless last_output if EXPECTED_POWER_ACTION_MESSAGES . any? { | message | last_output [ 'output' ] =~ / #{ message } / } @expecting_disconnect = true end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decide if the execution should fail or not [CODESPLIT] def exit_code fail_chance = ENV . fetch ( 'REX_SIMULATE_FAIL_CHANCE' , 0 ) . to_i fail_exitcode = ENV . fetch ( 'REX_SIMULATE_EXIT' , 0 ) . to_i if fail_exitcode == 0 || fail_chance < ( Random . rand * 100 ) . round 0 else fail_exitcode end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register a new function [CODESPLIT] def register ( name , fn = nil , & block ) self . class . new ( methods . merge ( name => fn || block ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Imports proc ( s ) to the collection from another module [CODESPLIT] def import ( * args ) first = args . first return import_all ( first ) if first . instance_of? ( Module ) opts = args . pop source = opts . fetch ( :from ) rename = opts . fetch ( :as ) { first . to_sym } return import_methods ( source , args ) if args . count > 1 import_method ( source , first , rename ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new immutable collection from the current one updated with either the module s singleton method or the proc having been imported from another module . [CODESPLIT] def import_method ( source , name , new_name = name ) from = name . to_sym to = new_name . to_sym fn = source . is_a? ( Registry ) ? source . fetch ( from ) : source . method ( from ) self . class . new ( methods . merge ( to => fn ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new immutable collection from the current one updated with either the module s singleton methods or the procs having been imported from another module . [CODESPLIT] def import_methods ( source , names ) names . inject ( self ) { | a , e | a . import_method ( source , e ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new immutable collection from the current one updated with all singleton methods and imported methods from the other module [CODESPLIT] def import_all ( source ) names = source . public_methods - Registry . instance_methods - Module . methods names -= [ :initialize ] # for compatibility with Rubinius names += source . store . methods . keys if source . is_a? Registry import_methods ( source , names ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds the transformation [CODESPLIT] def [] ( fn , * args ) fetched = fetch ( fn ) return Function . new ( fetched , args : args , name : fn ) unless already_wrapped? ( fetched ) args . empty? ? fetched : fetched . with ( args ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register a new function [CODESPLIT] def register ( name , fn = nil , & block ) if contain? ( name ) raise FunctionAlreadyRegisteredError , \"Function #{name} is already defined\" end @store = store . register ( name , fn , block ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets the procedure for creating a transproc [CODESPLIT] def fetch ( fn ) return fn unless fn . instance_of? Symbol respond_to? ( fn ) ? method ( fn ) : store . fetch ( fn ) rescue raise FunctionNotFoundError . new ( fn , self ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a simple AST representation of this function [CODESPLIT] def to_ast args_ast = args . map { | arg | arg . respond_to? ( :to_ast ) ? arg . to_ast : arg } [ name , args_ast ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts a transproc to a simple proc [CODESPLIT] def to_proc if args . size > 0 proc { | * value | fn . call ( value , args ) } else fn . to_proc end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Maps replacement keys to their values [CODESPLIT] def from_pattern_match ( keys , pattern , match ) keys . each_with_index . map do | key , idx | # Check if there is any replacement specified if pattern [ key ] interpolate ( pattern [ key ] , match ) else # No replacement defined, just return correct match group match [ idx + 1 ] end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Interpolates a string with data from matches if specified [CODESPLIT] def interpolate ( replacement , match ) group_idx = replacement . index ( '$' ) return replacement if group_idx . nil? group_nbr = replacement [ group_idx + 1 ] replacement . sub ( \"$#{group_nbr}\" , match [ group_nbr . to_i ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run commands prior to each tab context . [CODESPLIT] def before ( * commands , & block ) context = ( @_context [ :before ] ||= [ ] ) block_given? ? run_context ( context , block ) : context . concat ( commands ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run commands in the conext of a window . [CODESPLIT] def window ( * args , & block ) key = \"window#{@_windows.keys.size}\" options = args . extract_options! options [ :name ] = args . first unless args . empty? context = ( @_windows [ key ] = window_hash . merge ( :options => options ) ) run_context context , block end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run commands in the context of a tab . [CODESPLIT] def tab ( * args , & block ) tabs = @_context [ :tabs ] key = \"tab#{tabs.keys.size}\" return ( tabs [ key ] = { :commands => args } ) unless block_given? context = ( tabs [ key ] = { :commands => [ ] } ) options = args . extract_options! options [ :name ] = args . first unless args . empty? context [ :options ] = options run_context context , block @_context = @_windows [ @_windows . keys . last ] # Jump back out into the context of the last window. end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Store commands to run in context . [CODESPLIT] def run ( * commands ) context = case when @_context . is_a? ( Hash ) && @_context [ :tabs ] @_context [ :tabs ] [ 'default' ] [ :commands ] when @_context . is_a? ( Hash ) @_context [ :commands ] else @_context end context << commands . map { | c | c =~ / / ? \"(#{c})\" : c } . join ( \" && \" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for write operations [CODESPLIT] def set_write ( policy , operation , key , bins ) begin_cmd field_count = estimate_key_size ( key , policy ) bins . each do | bin | estimate_operation_size_for_bin ( bin ) end size_buffer write_header_with_policy ( policy , 0 , INFO2_WRITE , field_count , bins . length ) write_key ( key , policy ) bins . each do | bin | write_operation_for_bin ( bin , operation ) end end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for delete operations [CODESPLIT] def set_delete ( policy , key ) begin_cmd field_count = estimate_key_size ( key ) size_buffer write_header_with_policy ( policy , 0 , INFO2_WRITE | INFO2_DELETE , field_count , 0 ) write_key ( key ) end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for touch operations [CODESPLIT] def set_touch ( policy , key ) begin_cmd field_count = estimate_key_size ( key ) estimate_operation_size size_buffer write_header_with_policy ( policy , 0 , INFO2_WRITE , field_count , 1 ) write_key ( key ) write_operation_for_operation_type ( Aerospike :: Operation :: TOUCH ) end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for exist operations [CODESPLIT] def set_exists ( policy , key ) begin_cmd field_count = estimate_key_size ( key ) size_buffer write_header ( policy , INFO1_READ | INFO1_NOBINDATA , 0 , field_count , 0 ) write_key ( key ) end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for get operations ( all bins ) [CODESPLIT] def set_read_for_key_only ( policy , key ) begin_cmd field_count = estimate_key_size ( key ) size_buffer write_header ( policy , INFO1_READ | INFO1_GET_ALL , 0 , field_count , 0 ) write_key ( key ) end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for get operations ( specified bins ) [CODESPLIT] def set_read ( policy , key , bin_names ) if bin_names && bin_names . length > 0 begin_cmd field_count = estimate_key_size ( key ) bin_names . each do | bin_name | estimate_operation_size_for_bin_name ( bin_name ) end size_buffer write_header ( policy , INFO1_READ , 0 , field_count , bin_names . length ) write_key ( key ) bin_names . each do | bin_name | write_operation_for_bin_name ( bin_name , Aerospike :: Operation :: READ ) end end_cmd else set_read_for_key_only ( policy , key ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes the command for getting metadata operations [CODESPLIT] def set_read_header ( policy , key ) begin_cmd field_count = estimate_key_size ( key ) estimate_operation_size_for_bin_name ( '' ) size_buffer # The server does not currently return record header data with _INFO1_NOBINDATA attribute set. # The workaround is to request a non-existent bin. # TODO: Fix this on server. #command.set_read(INFO1_READ | _INFO1_NOBINDATA); write_header ( policy , INFO1_READ , 0 , field_count , 1 ) write_key ( key ) write_operation_for_bin_name ( '' , Aerospike :: Operation :: READ ) end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Implements different command operations [CODESPLIT] def set_operate ( policy , key , operations ) begin_cmd field_count = estimate_key_size ( key , policy ) read_attr = 0 write_attr = 0 read_header = false operations . each do | operation | case operation . op_type when Aerospike :: Operation :: READ read_attr |= INFO1_READ # Read all bins if no bin is specified. read_attr |= INFO1_GET_ALL unless operation . bin_name when Aerospike :: Operation :: READ_HEADER # The server does not currently return record header data with _INFO1_NOBINDATA attribute set. # The workaround is to request a non-existent bin. # TODO: Fix this on server. # read_attr |= _INFO1_READ | _INFO1_NOBINDATA read_attr |= INFO1_READ read_header = true else write_attr = INFO2_WRITE end estimate_operation_size_for_operation ( operation ) end size_buffer if write_attr != 0 write_header_with_policy ( policy , read_attr , write_attr , field_count , operations . length ) else write_header ( policy , read_attr , write_attr , field_count , operations . length ) end write_key ( key , policy ) operations . each do | operation | write_operation_for_operation ( operation ) end write_operation_for_bin ( nil , Aerospike :: Operation :: READ ) if read_header end_cmd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generic header write . [CODESPLIT] def write_header ( policy , read_attr , write_attr , field_count , operation_count ) read_attr |= INFO1_CONSISTENCY_ALL if policy . consistency_level == Aerospike :: ConsistencyLevel :: CONSISTENCY_ALL # Write all header data except total size which must be written last. @data_buffer . write_byte ( MSG_REMAINING_HEADER_SIZE , 8 ) # Message heade.length. @data_buffer . write_byte ( read_attr , 9 ) @data_buffer . write_byte ( write_attr , 10 ) i = 11 while i <= 25 @data_buffer . write_byte ( 0 , i ) i = i . succ end @data_buffer . write_int16 ( field_count , 26 ) @data_buffer . write_int16 ( operation_count , 28 ) @data_offset = MSG_TOTAL_HEADER_SIZE end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Header write for write operations . [CODESPLIT] def write_header_with_policy ( policy , read_attr , write_attr , field_count , operation_count ) # Set flags. generation = Integer ( 0 ) info_attr = Integer ( 0 ) case policy . record_exists_action when Aerospike :: RecordExistsAction :: UPDATE when Aerospike :: RecordExistsAction :: UPDATE_ONLY info_attr |= INFO3_UPDATE_ONLY when Aerospike :: RecordExistsAction :: REPLACE info_attr |= INFO3_CREATE_OR_REPLACE when Aerospike :: RecordExistsAction :: REPLACE_ONLY info_attr |= INFO3_REPLACE_ONLY when Aerospike :: RecordExistsAction :: CREATE_ONLY write_attr |= INFO2_CREATE_ONLY end case policy . generation_policy when Aerospike :: GenerationPolicy :: NONE when Aerospike :: GenerationPolicy :: EXPECT_GEN_EQUAL generation = policy . generation write_attr |= INFO2_GENERATION when Aerospike :: GenerationPolicy :: EXPECT_GEN_GT generation = policy . generation write_attr |= INFO2_GENERATION_GT end info_attr |= INFO3_COMMIT_MASTER if policy . commit_level == Aerospike :: CommitLevel :: COMMIT_MASTER read_attr |= INFO1_CONSISTENCY_ALL if policy . consistency_level == Aerospike :: ConsistencyLevel :: CONSISTENCY_ALL write_attr |= INFO2_DURABLE_DELETE if policy . durable_delete # Write all header data except total size which must be written last. @data_buffer . write_byte ( MSG_REMAINING_HEADER_SIZE , 8 ) # Message heade.length. @data_buffer . write_byte ( read_attr , 9 ) @data_buffer . write_byte ( write_attr , 10 ) @data_buffer . write_byte ( info_attr , 11 ) @data_buffer . write_byte ( 0 , 12 ) # unused @data_buffer . write_byte ( 0 , 13 ) # clear the result code @data_buffer . write_uint32 ( generation , 14 ) @data_buffer . write_uint32 ( policy . ttl , 18 ) # Initialize timeout. It will be written later. @data_buffer . write_byte ( 0 , 22 ) @data_buffer . write_byte ( 0 , 23 ) @data_buffer . write_byte ( 0 , 24 ) @data_buffer . write_byte ( 0 , 25 ) @data_buffer . write_int16 ( field_count , 26 ) @data_buffer . write_int16 ( operation_count , 28 ) @data_offset = MSG_TOTAL_HEADER_SIZE end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "NewExecuteTask initializes task with fields needed to query server nodes . IsDone queries all nodes for task completion status . [CODESPLIT] def all_nodes_done? if @scan command = 'scan-list' else command = 'query-list' end nodes = @cluster . nodes done = false nodes . each do | node | conn = node . get_connection ( 0 ) responseMap , _ = Info . request ( conn , command ) node . put_connection ( conn ) response = responseMap [ command ] find = \"job_id=#{@task_id}:\" index = response . index ( find ) unless index # don't return on first check done = true next end b = index + find . length response = response [ b , response . length ] find = 'job_status=' index = response . index ( find ) next unless index b = index + find . length response = response [ b , response . length ] e = response . index ( ':' ) status = response [ 0 , e ] case status when 'ABORTED' raise raise Aerospike :: Exceptions :: QueryTerminated when 'IN PROGRESS' return false when 'DONE' done = true end end done end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse all results in the batch . Add records to shared list . If the record was not found the bins will be nil . [CODESPLIT] def parse_row ( result_code ) generation = @data_buffer . read_int32 ( 6 ) expiration = @data_buffer . read_int32 ( 10 ) batch_index = @data_buffer . read_int32 ( 14 ) field_count = @data_buffer . read_int16 ( 18 ) op_count = @data_buffer . read_int16 ( 20 ) key = parse_key ( field_count ) req_key = batch . key_for_index ( batch_index ) if key . digest == req_key . digest if result_code == 0 record = parse_record ( req_key , op_count , generation , expiration ) results [ batch_index ] = record end else Aerospike . logger . warn ( \"Unexpected batch key returned: #{key}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Parse all results in the batch . Add records to shared list . If the record was not found the bins will be nil . [CODESPLIT] def parse_row ( result_code ) batch_index = @data_buffer . read_int32 ( 14 ) field_count = @data_buffer . read_int16 ( 18 ) op_count = @data_buffer . read_int16 ( 20 ) if op_count > 0 raise Aerospike :: Exceptions :: Parse . new ( 'Received bins that were not requested!' ) end parse_key ( field_count ) results [ batch_index ] = ( result_code == 0 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Parse all results in the batch . Add records to shared list . If the record was not found the bins will be nil . [CODESPLIT] def parse_row ( result_code ) field_count = @data_buffer . read_int16 ( 18 ) op_count = @data_buffer . read_int16 ( 20 ) if op_count > 0 raise Aerospike :: Exceptions :: Parse . new ( 'Received bins that were not requested!' ) end key = parse_key ( field_count ) item = key_map [ key . digest ] if item index = item . index results [ index ] = ( result_code == 0 ) else Aerospike :: logger . debug ( \"Unexpected batch key returned: #{key.namespace}, #{key.digest}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse all results in the batch . Add records to shared list . If the record was not found the bins will be nil . [CODESPLIT] def parse_row ( result_code ) generation = @data_buffer . read_int32 ( 6 ) expiration = @data_buffer . read_int32 ( 10 ) field_count = @data_buffer . read_int16 ( 18 ) op_count = @data_buffer . read_int16 ( 20 ) key = parse_key ( field_count ) item = key_map [ key . digest ] if item if result_code == 0 index = item . index key = item . key results [ index ] = parse_record ( key , op_count , generation , expiration ) end else Aerospike . logger . warn ( \"Unexpected batch key returned: #{key}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def write_bins @operations . select { | op | op . op_type == Aerospike :: Operation :: WRITE } . map ( :bin ) . compact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def update_partition ( nmap , node ) amap = nil copied = false while partition = get_next node_array = nmap [ partition . namespace ] if ! node_array if ! copied # Make shallow copy of map. amap = { } nmap . each { | k , v | amap [ k ] = v } copied = true end node_array = Atomic . new ( Array . new ( Aerospike :: Node :: PARTITIONS ) ) amap [ partition . namespace ] = node_array end Aerospike . logger . debug ( \"#{partition.to_s}, #{node.name}\" ) node_array . update { | v | v [ partition . partition_id ] = node ; v } end copied ? amap : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialize server node with connection parameters . Get a connection to the node . If no cached connection is not available a new connection will be created [CODESPLIT] def get_connection ( timeout ) loop do conn = @connections . poll if conn . connected? conn . timeout = timeout . to_f return conn end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def write_buffer fieldCount = 0 filterSize = 0 binNameSize = 0 begin_cmd if @statement . namespace @data_offset += @statement . namespace . bytesize + FIELD_HEADER_SIZE fieldCount += 1 end if @statement . index_name @data_offset += @statement . index_name . bytesize + FIELD_HEADER_SIZE fieldCount += 1 end if @statement . set_name @data_offset += @statement . set_name . bytesize + FIELD_HEADER_SIZE fieldCount += 1 end if ! is_scan? col_type = @statement . filters [ 0 ] . collection_type if col_type > 0 @data_offset += FIELD_HEADER_SIZE + 1 fieldCount += 1 end @data_offset += FIELD_HEADER_SIZE filterSize += 1 # num filters @statement . filters . each do | filter | sz = filter . estimate_size filterSize += sz end @data_offset += filterSize fieldCount += 1 if @statement . bin_names && @statement . bin_names . length > 0 @data_offset += FIELD_HEADER_SIZE binNameSize += 1 # num bin names @statement . bin_names . each do | bin_name | binNameSize += bin_name . bytesize + 1 end @data_offset += binNameSize fieldCount += 1 end else # Calling query with no filters is more efficiently handled by a primary index scan. # Estimate scan options size. @data_offset += ( 2 + FIELD_HEADER_SIZE ) fieldCount += 1 end @statement . set_task_id @data_offset += 8 + FIELD_HEADER_SIZE fieldCount += 1 if @statement . function_name @data_offset += FIELD_HEADER_SIZE + 1 # udf type @data_offset += @statement . package_name . bytesize + FIELD_HEADER_SIZE @data_offset += @statement . function_name . bytesize + FIELD_HEADER_SIZE if @statement . function_args && @statement . function_args . length > 0 functionArgBuffer = Value . of ( @statement . function_args ) . to_bytes else functionArgBuffer = '' end @data_offset += FIELD_HEADER_SIZE + functionArgBuffer . bytesize fieldCount += 4 end if @statement . filters . nil? || @statement . filters . empty? if @statement . bin_names && @statement . bin_names . length > 0 @statement . bin_names . each do | bin_name | estimate_operation_size_for_bin_name ( bin_name ) end end end size_buffer readAttr = @policy . include_bin_data ? INFO1_READ : INFO1_READ | INFO1_NOBINDATA operation_count = ( is_scan? && ! @statement . bin_names . nil? ) ? @statement . bin_names . length : 0 write_header ( @policy , readAttr , 0 , fieldCount , operation_count ) if @statement . namespace write_field_string ( @statement . namespace , Aerospike :: FieldType :: NAMESPACE ) end unless @statement . index_name . nil? write_field_string ( @statement . index_name , Aerospike :: FieldType :: INDEX_NAME ) end if @statement . set_name write_field_string ( @statement . set_name , Aerospike :: FieldType :: TABLE ) end if ! is_scan? col_type = @statement . filters [ 0 ] . collection_type if col_type > 0 write_field_header ( 1 , Aerospike :: FieldType :: INDEX_TYPE ) @data_buffer . write_byte ( col_type , @data_offset ) @data_offset += 1 end write_field_header ( filterSize , Aerospike :: FieldType :: INDEX_RANGE ) @data_buffer . write_byte ( @statement . filters . length , @data_offset ) @data_offset += 1 @statement . filters . each do | filter | @data_offset = filter . write ( @data_buffer , @data_offset ) end # Query bin names are specified as a field (Scan bin names are specified later as operations) if @statement . bin_names && @statement . bin_names . length > 0 write_field_header ( binNameSize , Aerospike :: FieldType :: QUERY_BINLIST ) @data_buffer . write_byte ( @statement . bin_names . length , @data_offset ) @data_offset += 1 @statement . bin_names . each do | bin_name | len = @data_buffer . write_binary ( bin_name , @data_offset + 1 ) @data_buffer . write_byte ( len , @data_offset ) @data_offset += len + 1 ; end end else # Calling query with no filters is more efficiently handled by a primary index scan. write_field_header ( 2 , Aerospike :: FieldType :: SCAN_OPTIONS ) priority = @policy . priority . ord priority = priority << 4 @data_buffer . write_byte ( priority , @data_offset ) @data_offset += 1 @data_buffer . write_byte ( 100 . ord , @data_offset ) @data_offset += 1 end write_field_header ( 8 , Aerospike :: FieldType :: TRAN_ID ) @data_buffer . write_int64 ( @statement . task_id , @data_offset ) @data_offset += 8 if @statement . function_name write_field_header ( 1 , Aerospike :: FieldType :: UDF_OP ) if @statement . return_data @data_buffer . write_byte ( 1 , @data_offset ) @data_offset += 1 else @data_buffer . write_byte ( 2 , @data_offset ) @data_offset += 1 end write_field_string ( @statement . package_name , Aerospike :: FieldType :: UDF_PACKAGE_NAME ) write_field_string ( @statement . function_name , Aerospike :: FieldType :: UDF_FUNCTION ) write_field_bytes ( functionArgBuffer , Aerospike :: FieldType :: UDF_ARGLIST ) end if is_scan? && ! @statement . bin_names . nil? @statement . bin_names . each do | bin_name | write_operation_for_bin_name ( bin_name , Aerospike :: Operation :: READ ) end end end_cmd return nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def parse_group ( receive_size ) @data_offset = 0 while @data_offset < receive_size read_bytes ( MSG_REMAINING_HEADER_SIZE ) result_code = @data_buffer . read ( 5 ) . ord & 0xFF # The only valid server return codes are \"ok\" and \"not found\". # If other return codes are received, then abort the batch. case result_code when Aerospike :: ResultCode :: OK # noop when Aerospike :: ResultCode :: KEY_NOT_FOUND_ERROR # consume the rest of the input buffer from the socket read_bytes ( receive_size - @data_offset ) if @data_offset < receive_size return nil else raise Aerospike :: Exceptions :: Aerospike . new ( result_code ) end info3 = @data_buffer . read ( 3 ) . ord # If cmd is the end marker of the response, do not proceed further return false if ( info3 & INFO3_LAST ) == INFO3_LAST generation = @data_buffer . read_int32 ( 6 ) expiration = @data_buffer . read_int32 ( 10 ) field_count = @data_buffer . read_int16 ( 18 ) op_count = @data_buffer . read_int16 ( 20 ) key = parse_key ( field_count ) if result_code == 0 if @recordset . active? @recordset . records . enq ( parse_record ( key , op_count , generation , expiration ) ) else expn = @recordset . is_scan? ? SCAN_TERMINATED_EXCEPTION : QUERY_TERMINATED_EXCEPTION raise expn end end end # while true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def parse_result # Read socket into receive buffer one record at a time.  Do not read entire receive size # because the receive buffer would be too big. status = true while status # Read header. read_bytes ( 8 ) size = @data_buffer . read_int64 ( 0 ) receive_size = size & 0xFFFFFFFFFFFF if receive_size > 0 status = parse_group ( receive_size ) else status = false end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parses the given byte buffer and populate the result object . Returns the number of bytes that were parsed from the given buffer . [CODESPLIT] def parse_record ( key , op_count , generation , expiration ) bins = op_count > 0 ? { } : nil i = 0 while i < op_count raise Aerospike :: Exceptions :: QueryTerminated . new unless valid? read_bytes ( 8 ) op_size = @data_buffer . read_int32 ( 0 ) . ord particle_type = @data_buffer . read ( 5 ) . ord name_size = @data_buffer . read ( 7 ) . ord read_bytes ( name_size ) name = @data_buffer . read ( 0 , name_size ) . force_encoding ( 'utf-8' ) particle_bytes_size = op_size - ( 4 + name_size ) read_bytes ( particle_bytes_size ) value = Aerospike . bytes_to_particle ( particle_type , @data_buffer , 0 , particle_bytes_size ) bins [ name ] = value i = i . succ end Record . new ( @node , key , bins , generation , expiration ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def update_partition ( nmap , node ) amap = nil beginning = @offset copied = false while @offset < @length if @buffer [ @offset ] == ':' # Parse namespace. namespace = @buffer [ beginning ... @offset ] . strip if namespace . length <= 0 || namespace . length >= 32 response = get_truncated_response raise Aerospike :: Exceptions :: Parse . new ( \"Invalid partition namespace #{namespace}. Response=#{response}\" ) end @offset += 1 beginning = @offset # Parse partition id. while @offset < @length b = @buffer [ @offset ] break if b == ';' || b == \"\\n\" @offset += 1 end if @offset == beginning response = get_truncated_response raise Aerospike :: Exceptions :: Parse . new ( \"Empty partition id for namespace #{namespace}. Response=#{response}\" ) end node_array = nmap [ namespace ] if ! node_array if ! copied # Make shallow copy of map. amap = { } nmap . each { | k , v | amap [ k ] = Atomic . new ( v ) } copied = true end node_array = Atomic . new ( Array . new ( Aerospike :: Node :: PARTITIONS ) ) amap [ namespace ] = node_array end bit_map_length = @offset - beginning restore_buffer = Base64 . strict_decode64 ( @buffer [ beginning , bit_map_length ] ) i = 0 while i < Aerospike :: Node :: PARTITIONS if ( restore_buffer [ i >> 3 ] . ord & ( 0x80 >> ( i & 7 ) ) ) != 0 # Logger.Info(\"Map: `\" + namespace + \"`,\" + strconv.Itoa(i) + \",\" + node.String) node_array . update { | v | v [ i ] = node ; v } end i = i . succ end @offset += 1 beginning = @offset else @offset += 1 end end copied ? amap : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts an absolute expiration time ( in seconds from citrusleaf epoch ) to relative time - to - live ( TTL ) in seconds [CODESPLIT] def expiration_to_ttl ( secs_from_epoc ) if secs_from_epoc == 0 Aerospike :: TTL :: NEVER_EXPIRE else now = Time . now . to_i - CITRUSLEAF_EPOCH # Record was not expired at server but if it looks expired at client # because of delay or clock differences, present it as not-expired. secs_from_epoc > now ? secs_from_epoc - now : 1 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a random node on the cluster [CODESPLIT] def random_node # Must copy array reference for copy on write semantics to work. node_array = nodes length = node_array . length i = 0 while i < length # Must handle concurrency with other non-tending threads, so node_index is consistent. index = ( @node_index . update { | v | v + 1 } % node_array . length ) . abs node = node_array [ index ] return node if node . active? i = i . succ end raise Aerospike :: Exceptions :: InvalidNode end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find a node by name and returns an error if not found [CODESPLIT] def get_node_by_name ( node_name ) node = find_node_by_name ( node_name ) raise Aerospike :: Exceptions :: InvalidNode unless node node end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Refresh status of all nodes in cluster . Adds new nodes and / or removes unhealty ones [CODESPLIT] def refresh_nodes cluster_config_changed = false nodes = self . nodes if nodes . empty? seed_nodes cluster_config_changed = true nodes = self . nodes end peers = Peers . new # Clear node reference count nodes . each do | node | node . refresh_reset end peers . use_peers = supports_peers_protocol? # refresh all known nodes nodes . each do | node | node . refresh_info ( peers ) end # refresh peers when necessary if peers . generation_changed? # Refresh peers for all nodes that responded the first time even if only # one node's peers changed. peers . reset_refresh_count! nodes . each do | node | node . refresh_peers ( peers ) end end nodes . each do | node | node . refresh_partitions ( peers ) if node . partition_generation . changed? end if peers . generation_changed? || ! peers . use_peers? nodes_to_remove = find_nodes_to_remove ( peers . refresh_count ) if nodes_to_remove . any? remove_nodes ( nodes_to_remove ) cluster_config_changed = true end end # Add any new nodes from peer refresh if peers . nodes . any? # peers.nodes is a Hash. Pass only values, ie. the array of nodes add_nodes ( peers . nodes . values ) cluster_config_changed = true end cluster_config_changed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Write Record Operations ------------------------------------------------------- [CODESPLIT] def put ( key , bins , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = WriteCommand . new ( @cluster , policy , key , hash_to_bins ( bins ) , Aerospike :: Operation :: WRITE ) execute_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Operations string ------------------------------------------------------- [CODESPLIT] def append ( key , bins , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = WriteCommand . new ( @cluster , policy , key , hash_to_bins ( bins ) , Aerospike :: Operation :: APPEND ) execute_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepends bin values string to existing record bin values . The policy specifies the transaction timeout record expiration and how the transaction is handled when the record already exists . [CODESPLIT] def prepend ( key , bins , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = WriteCommand . new ( @cluster , policy , key , hash_to_bins ( bins ) , Aerospike :: Operation :: PREPEND ) execute_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Arithmetic Operations ------------------------------------------------------- [CODESPLIT] def add ( key , bins , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = WriteCommand . new ( @cluster , policy , key , hash_to_bins ( bins ) , Aerospike :: Operation :: ADD ) execute_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Delete Operations ------------------------------------------------------- [CODESPLIT] def delete ( key , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = DeleteCommand . new ( @cluster , policy , key ) execute_command ( command ) command . existed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes records in the specified namespace / set efficiently . [CODESPLIT] def truncate ( namespace , set_name = nil , before_last_update = nil , options = { } ) policy = create_policy ( options , Policy , default_info_policy ) str_cmd = \"truncate:namespace=#{namespace}\" str_cmd << \";set=#{set_name}\" unless set_name . to_s . strip . empty? if before_last_update lut_nanos = ( before_last_update . to_f * 1_000_000_000.0 ) . round str_cmd << \";lut=#{lut_nanos}\" elsif supports_feature? ( Aerospike :: Features :: LUT_NOW ) # Servers >= 4.3.1.4 require lut argument str_cmd << \";lut=now\" end # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command ( policy , str_cmd ) . upcase return if response == 'OK' raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: SERVER_ERROR , \"Truncate failed: #{response}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Touch Operations ------------------------------------------------------- [CODESPLIT] def touch ( key , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = TouchCommand . new ( @cluster , policy , key ) execute_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Existence - Check Operations ------------------------------------------------------- [CODESPLIT] def exists ( key , options = nil ) policy = create_policy ( options , Policy , default_read_policy ) command = ExistsCommand . new ( @cluster , policy , key ) execute_command ( command ) command . exists end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Read Record Operations ------------------------------------------------------- Read record header and bins for specified key . The policy can be used to specify timeouts . [CODESPLIT] def get ( key , bin_names = nil , options = nil ) policy = create_policy ( options , Policy , default_read_policy ) command = ReadCommand . new ( @cluster , policy , key , bin_names ) execute_command ( command ) command . record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read record generation and expiration only for specified key . Bins are not read . The policy can be used to specify timeouts . [CODESPLIT] def get_header ( key , options = nil ) policy = create_policy ( options , Policy , default_read_policy ) command = ReadHeaderCommand . new ( @cluster , policy , key ) execute_command ( command ) command . record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Batch Read Operations ------------------------------------------------------- Read multiple record headers and bins for specified keys in one batch call . The returned records are in positional order with the original key array order . If a key is not found the positional record will be nil . The policy can be used to specify timeouts and protocol type . [CODESPLIT] def batch_get ( keys , bin_names = nil , options = nil ) policy = create_policy ( options , BatchPolicy , default_batch_policy ) results = Array . new ( keys . length ) info_flags = INFO1_READ case bin_names when :all , nil , [ ] info_flags |= INFO1_GET_ALL bin_names = nil when :none info_flags |= INFO1_NOBINDATA bin_names = nil end if policy . use_batch_direct key_map = BatchItem . generate_map ( keys ) execute_batch_direct_commands ( keys ) do | node , batch | BatchDirectCommand . new ( node , batch , policy , key_map , bin_names , results , info_flags ) end else execute_batch_index_commands ( keys ) do | node , batch | BatchIndexCommand . new ( node , batch , policy , bin_names , results , info_flags ) end end results end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if multiple record keys exist in one batch call . The returned boolean array is in positional order with the original key array order . The policy can be used to specify timeouts and protocol type . [CODESPLIT] def batch_exists ( keys , options = nil ) policy = create_policy ( options , BatchPolicy , default_batch_policy ) results = Array . new ( keys . length ) if policy . use_batch_direct key_map = BatchItem . generate_map ( keys ) execute_batch_direct_commands ( keys ) do | node , batch | BatchDirectExistsCommand . new ( node , batch , policy , key_map , results ) end else execute_batch_index_commands ( keys ) do | node , batch | BatchIndexExistsCommand . new ( node , batch , policy , results ) end end results end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Generic Database Operations ------------------------------------------------------- Perform multiple read / write operations on a single key in one batch call . An example would be to add an integer value to an existing record and then read the result all in one database call . Operations are executed in the order they are specified . [CODESPLIT] def operate ( key , operations , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = OperateCommand . new ( @cluster , policy , key , operations ) execute_command ( command ) command . record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "--------------------------------------------------------------- User defined functions ( Supported by Aerospike 3 servers only ) --------------------------------------------------------------- Register package containing user defined functions with server . This asynchronous server call will return before command is complete . The user can optionally wait for command completion by using the returned RegisterTask instance . [CODESPLIT] def register_udf_from_file ( client_path , server_path , language , options = nil ) udf_body = File . read ( client_path ) register_udf ( udf_body , server_path , language , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register package containing user defined functions with server . This asynchronous server call will return before command is complete . The user can optionally wait for command completion by using the returned RegisterTask instance . [CODESPLIT] def register_udf ( udf_body , server_path , language , options = nil ) policy = create_policy ( options , Policy , default_info_policy ) content = Base64 . strict_encode64 ( udf_body ) . force_encoding ( 'binary' ) str_cmd = \"udf-put:filename=#{server_path};content=#{content};\" str_cmd << \"content-len=#{content.length};udf-type=#{language};\" # Send UDF to one node. That node will distribute the UDF to other nodes. response_map = @cluster . request_info ( policy , str_cmd ) res = { } response_map . each do | k , response | vals = response . to_s . split ( ';' ) vals . each do | pair | k , v = pair . split ( \"=\" , 2 ) res [ k ] = v end end if res [ 'error' ] raise Aerospike :: Exceptions :: CommandRejected . new ( \"Registration failed: #{res['error']}\\nFile: #{res['file']}\\nLine: #{res['line']}\\nMessage: #{res['message']}\" ) end UdfRegisterTask . new ( @cluster , server_path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "RemoveUDF removes a package containing user defined functions in the server . This asynchronous server call will return before command is complete . The user can optionally wait for command completion by using the returned RemoveTask instance . [CODESPLIT] def remove_udf ( udf_name , options = nil ) policy = create_policy ( options , Policy , default_info_policy ) str_cmd = \"udf-remove:filename=#{udf_name};\" # Send command to one node. That node will distribute it to other nodes. # Send UDF to one node. That node will distribute the UDF to other nodes. response_map = @cluster . request_info ( policy , str_cmd ) _ , response = response_map . first if response == 'ok' UdfRemoveTask . new ( @cluster , udf_name ) else raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: SERVER_ERROR , response ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "ListUDF lists all packages containing user defined functions in the server . This method is only supported by Aerospike 3 servers . [CODESPLIT] def list_udf ( options = nil ) policy = create_policy ( options , Policy , default_info_policy ) str_cmd = 'udf-list' # Send command to one node. That node will distribute it to other nodes. response_map = @cluster . request_info ( policy , str_cmd ) _ , response = response_map . first vals = response . split ( ';' ) vals . map do | udf_info | next if udf_info . strip! == '' udf_parts = udf_info . split ( ',' ) udf = UDF . new udf_parts . each do | values | k , v = values . split ( '=' , 2 ) case k when 'filename' udf . filename = v when 'hash' udf . hash = v when 'type' udf . language = v end end udf end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute user defined function on server and return results . The function operates on a single record . The package name is used to locate the udf file location : [CODESPLIT] def execute_udf ( key , package_name , function_name , args = [ ] , options = nil ) policy = create_policy ( options , WritePolicy , default_write_policy ) command = ExecuteCommand . new ( @cluster , policy , key , package_name , function_name , args ) execute_command ( command ) record = command . record return nil if ! record || record . bins . empty? result_map = record . bins # User defined functions don't have to return a value. key , obj = result_map . detect { | k , _ | k . include? ( 'SUCCESS' ) } return obj if key key , obj = result_map . detect { | k , _ | k . include? ( 'FAILURE' ) } message = key ? obj . to_s : \"Invalid UDF return value\" raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: UDF_BAD_RESPONSE , message ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "execute_udf_on_query applies user defined function on records that match the statement filter . Records are not returned to the client . This asynchronous server call will return before command is complete . The user can optionally wait for command completion by using the returned ExecuteTask instance . [CODESPLIT] def execute_udf_on_query ( statement , package_name , function_name , function_args = [ ] , options = nil ) policy = create_policy ( options , QueryPolicy , default_query_policy ) nodes = @cluster . nodes if nodes . empty? raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: SERVER_NOT_AVAILABLE , \"Executing UDF failed because cluster is empty.\" ) end # TODO: wait until all migrations are finished statement . set_aggregate_function ( package_name , function_name , function_args , false ) # Use a thread per node nodes . each do | node | Thread . new do Thread . current . abort_on_exception = true begin command = QueryCommand . new ( node , policy , statement , nil ) execute_command ( command ) rescue => e Aerospike . logger . error ( e ) raise e end end end ExecuteTask . new ( @cluster , statement ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create secondary index . This asynchronous server call will return before command is complete . The user can optionally wait for command completion by using the returned IndexTask instance . [CODESPLIT] def create_index ( namespace , set_name , index_name , bin_name , index_type , collection_type = nil , options = nil ) if options . nil? && collection_type . is_a? ( Hash ) options , collection_type = collection_type , nil end policy = create_policy ( options , Policy , default_info_policy ) str_cmd = \"sindex-create:ns=#{namespace}\" str_cmd << \";set=#{set_name}\" unless set_name . to_s . strip . empty? str_cmd << \";indexname=#{index_name};numbins=1\" str_cmd << \";indextype=#{collection_type.to_s.upcase}\" if collection_type str_cmd << \";indexdata=#{bin_name},#{index_type.to_s.upcase}\" str_cmd << \";priority=normal\" # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command ( policy , str_cmd ) . upcase if response == 'OK' # Return task that could optionally be polled for completion. return IndexTask . new ( @cluster , namespace , index_name ) end if response . start_with? ( 'FAIL:200' ) # Index has already been created.  Do not need to poll for completion. return IndexTask . new ( @cluster , namespace , index_name , true ) end raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: INDEX_GENERIC , \"Create index failed: #{response}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete secondary index . This method is only supported by Aerospike 3 servers . [CODESPLIT] def drop_index ( namespace , set_name , index_name , options = nil ) policy = create_policy ( options , Policy , default_info_policy ) str_cmd = \"sindex-delete:ns=#{namespace}\" str_cmd << \";set=#{set_name}\" unless set_name . to_s . strip . empty? str_cmd << \";indexname=#{index_name}\" # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command ( policy , str_cmd ) . upcase return if response == 'OK' # Index did not previously exist. Return without error. return if response . start_with? ( 'FAIL:201' ) raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: INDEX_GENERIC , \"Drop index failed: #{response}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- Scan Operations ------------------------------------------------------- [CODESPLIT] def scan_all ( namespace , set_name , bin_names = nil , options = nil ) policy = create_policy ( options , ScanPolicy , default_scan_policy ) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # Retry policy must be one-shot for scans. # copy on write for policy new_policy = policy . clone nodes = @cluster . nodes if nodes . empty? raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: SERVER_NOT_AVAILABLE , \"Scan failed because cluster is empty.\" ) end recordset = Recordset . new ( policy . record_queue_size , nodes . length , :scan ) if policy . concurrent_nodes # Use a thread per node nodes . each do | node | Thread . new do Thread . current . abort_on_exception = true command = ScanCommand . new ( node , new_policy , namespace , set_name , bin_names , recordset ) begin execute_command ( command ) rescue => e Aerospike . logger . error ( e . backtrace . join ( \"\\n\" ) ) unless e == SCAN_TERMINATED_EXCEPTION recordset . cancel ( e ) ensure recordset . thread_finished end end end else Thread . new do Thread . current . abort_on_exception = true nodes . each do | node | command = ScanCommand . new ( node , new_policy , namespace , set_name , bin_names , recordset ) begin execute_command ( command ) rescue => e Aerospike . logger . error ( e . backtrace . join ( \"\\n\" ) ) unless e == SCAN_TERMINATED_EXCEPTION recordset . cancel ( e ) ensure recordset . thread_finished end end end end recordset end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "ScanNode reads all records in specified namespace and set from one node only . The policy can be used to specify timeouts . [CODESPLIT] def scan_node ( node , namespace , set_name , bin_names = nil , options = nil ) policy = create_policy ( options , ScanPolicy , default_scan_policy ) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # Retry policy must be one-shot for scans. # copy on write for policy new_policy = policy . clone new_policy . max_retries = 0 node = @cluster . get_node_by_name ( node ) unless node . is_a? ( Aerospike :: Node ) recordset = Recordset . new ( policy . record_queue_size , 1 , :scan ) Thread . new do Thread . current . abort_on_exception = true command = ScanCommand . new ( node , new_policy , namespace , set_name , bin_names , recordset ) begin execute_command ( command ) rescue => e Aerospike . logger . error ( e . backtrace . join ( \"\\n\" ) ) unless e == SCAN_TERMINATED_EXCEPTION recordset . cancel ( e ) ensure recordset . thread_finished end end recordset end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "-------------------------------------------------------- Query functions ( Supported by Aerospike 3 servers only ) -------------------------------------------------------- Query executes a query and returns a recordset . The query executor puts records on a channel from separate goroutines . The caller can concurrently pops records off the channel through the record channel . [CODESPLIT] def query ( statement , options = nil ) policy = create_policy ( options , QueryPolicy , default_query_policy ) new_policy = policy . clone nodes = @cluster . nodes if nodes . empty? raise Aerospike :: Exceptions :: Aerospike . new ( Aerospike :: ResultCode :: SERVER_NOT_AVAILABLE , \"Scan failed because cluster is empty.\" ) end recordset = Recordset . new ( policy . record_queue_size , nodes . length , :query ) # Use a thread per node nodes . each do | node | Thread . new do Thread . current . abort_on_exception = true command = QueryCommand . new ( node , new_policy , statement , recordset ) begin execute_command ( command ) rescue => e Aerospike . logger . error ( e . backtrace . join ( \"\\n\" ) ) unless e == QUERY_TERMINATED_EXCEPTION recordset . cancel ( e ) ensure recordset . thread_finished end end end recordset end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------- User administration ------------------------------------------------------- Create user with password and roles . Clear - text password will be hashed using bcrypt before sending to server . [CODESPLIT] def create_user ( user , password , roles , options = nil ) policy = create_policy ( options , AdminPolicy , default_admin_policy ) hash = AdminCommand . hash_password ( password ) command = AdminCommand . new command . create_user ( @cluster , policy , user , hash , roles ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove user from cluster . [CODESPLIT] def drop_user ( user , options = nil ) policy = create_policy ( options , AdminPolicy , default_admin_policy ) command = AdminCommand . new command . drop_user ( @cluster , policy , user ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Change user s password . Clear - text password will be hashed using bcrypt before sending to server . [CODESPLIT] def change_password ( user , password , options = nil ) raise Aerospike :: Exceptions :: Aerospike . new ( INVALID_USER ) unless @cluster . user && @cluster . user != \"\" policy = create_policy ( options , AdminPolicy , default_admin_policy ) hash = AdminCommand . hash_password ( password ) command = AdminCommand . new if user == @cluster . user # Change own password. command . change_password ( @cluster , policy , user , hash ) else # Change other user's password by user admin. command . set_password ( @cluster , policy , user , hash ) end @cluster . change_password ( user , hash ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add roles to user s list of roles . [CODESPLIT] def grant_roles ( user , roles , options = nil ) policy = create_policy ( options , AdminPolicy , default_admin_policy ) command = AdminCommand . new command . grant_roles ( @cluster , policy , user , roles ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve all users and their roles . [CODESPLIT] def query_users ( options = nil ) policy = create_policy ( options , AdminPolicy , default_admin_policy ) command = AdminCommand . new command . query_users ( @cluster , policy ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def authenticate ( conn , user , password ) begin set_authenticate ( user , password ) conn . write ( @data_buffer , @data_offset ) conn . read ( @data_buffer , HEADER_SIZE ) result = @data_buffer . read ( RESULT_CODE ) raise Exceptions :: Aerospike . new ( result , \"Authentication failed\" ) if result != 0 ensure Buffer . put ( @data_buffer ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fetches and return the first record from the queue if the operation is not finished and the queue is empty it blocks and waits for new records it sets the exception if it reaches the EOF mark and returns nil EOF means the operation has finished and no more records are comming from server nodes it re - raises the exception occurred in threads or which was set after reaching the EOF in the previous call [CODESPLIT] def next_record raise @thread_exception . get unless @thread_exception . get . nil? r = @records . deq set_exception if r . nil? r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fetches and returns all the records from the queue until the whole operation is finished and it reaches an EOF mark calling cancel inside the each block raises an exception to signal other consumer threads [CODESPLIT] def each ( & block ) r = true while r r = next_record # nil means EOF unless r . nil? block . call ( r ) else # reached the EOF break end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This helper allows custom data attributes to be added to a user for the current request from within the controller . e . g . [CODESPLIT] def intercom_custom_data @_request_specific_intercom_custom_data ||= begin s = Struct . new ( :user , :company ) . new s . user = { } s . company = { } s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate an intercom script tag . [CODESPLIT] def intercom_script_tag ( user_details = nil , options = { } ) controller . instance_variable_set ( IntercomRails :: SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE , true ) if defined? ( controller ) options [ :user_details ] = user_details if user_details . present? options [ :find_current_user_details ] = ! options [ :user_details ] options [ :find_current_company_details ] = ! ( options [ :user_details ] && options [ :user_details ] [ :company ] ) options [ :controller ] = controller if defined? ( controller ) ScriptTag . new ( options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Moves this object based on the forces being applied to it and performing collision checking . [CODESPLIT] def move ( forces , obst , ramps , set_speed = false ) if set_speed @speed . x = forces . x @speed . y = forces . y else forces . x += G . gravity . x ; forces . y += G . gravity . y forces . x += @stored_forces . x ; forces . y += @stored_forces . y @stored_forces . x = @stored_forces . y = 0 forces . x = 0 if ( forces . x < 0 and @left ) or ( forces . x > 0 and @right ) forces . y = 0 if ( forces . y < 0 and @top ) or ( forces . y > 0 and @bottom ) if @bottom . is_a? Ramp if @bottom . ratio > G . ramp_slip_threshold forces . x += ( @bottom . left ? - 1 : 1 ) * ( @bottom . ratio - G . ramp_slip_threshold ) * G . ramp_slip_force / G . ramp_slip_threshold elsif forces . x > 0 && @bottom . left || forces . x < 0 && ! @bottom . left forces . x *= @bottom . factor end end @speed . x += forces . x / @mass ; @speed . y += forces . y / @mass end @speed . x = 0 if @speed . x . abs < G . min_speed . x @speed . y = 0 if @speed . y . abs < G . min_speed . y @speed . x = ( @speed . x <=> 0 ) * @max_speed . x if @speed . x . abs > @max_speed . x @speed . y = ( @speed . y <=> 0 ) * @max_speed . y if @speed . y . abs > @max_speed . y @prev_speed = @speed . clone x = @speed . x < 0 ? @x + @speed . x : @x y = @speed . y < 0 ? @y + @speed . y : @y w = @w + ( @speed . x < 0 ? - @speed . x : @speed . x ) h = @h + ( @speed . y < 0 ? - @speed . y : @speed . y ) move_bounds = Rectangle . new x , y , w , h coll_list = [ ] obst . each do | o | coll_list << o if o != self && move_bounds . intersect? ( o . bounds ) end ramps . each do | r | r . check_can_collide move_bounds end if coll_list . length > 0 up = @speed . y < 0 ; rt = @speed . x > 0 ; dn = @speed . y > 0 ; lf = @speed . x < 0 if @speed . x == 0 || @speed . y == 0 # Ortogonal if rt ; x_lim = find_right_limit coll_list elsif lf ; x_lim = find_left_limit coll_list elsif dn ; y_lim = find_down_limit coll_list elsif up ; y_lim = find_up_limit coll_list end if rt && @x + @w + @speed . x > x_lim @x = x_lim - @w @speed . x = 0 elsif lf && @x + @speed . x < x_lim @x = x_lim @speed . x = 0 elsif dn && @y + @h + @speed . y > y_lim ; @y = y_lim - @h ; @speed . y = 0 elsif up && @y + @speed . y < y_lim ; @y = y_lim ; @speed . y = 0 end else # Diagonal x_aim = @x + @speed . x + ( rt ? @w : 0 ) ; x_lim_def = x_aim y_aim = @y + @speed . y + ( dn ? @h : 0 ) ; y_lim_def = y_aim coll_list . each do | c | if c . passable ; x_lim = x_aim elsif rt ; x_lim = c . x else ; x_lim = c . x + c . w end if dn ; y_lim = c . y elsif c . passable ; y_lim = y_aim else ; y_lim = c . y + c . h end if c . passable y_lim_def = y_lim if dn && @y + @h <= y_lim && y_lim < y_lim_def elsif ( rt && @x + @w > x_lim ) || ( lf && @x < x_lim ) # Can't limit by x, will limit by y y_lim_def = y_lim if ( dn && y_lim < y_lim_def ) || ( up && y_lim > y_lim_def ) elsif ( dn && @y + @h > y_lim ) || ( up && @y < y_lim ) # Can't limit by y, will limit by x x_lim_def = x_lim if ( rt && x_lim < x_lim_def ) || ( lf && x_lim > x_lim_def ) else x_time = 1.0 * ( x_lim - @x - ( @speed . x < 0 ? 0 : @w ) ) / @speed . x y_time = 1.0 * ( y_lim - @y - ( @speed . y < 0 ? 0 : @h ) ) / @speed . y if x_time > y_time # Will limit by x x_lim_def = x_lim if ( rt && x_lim < x_lim_def ) || ( lf && x_lim > x_lim_def ) elsif ( dn && y_lim < y_lim_def ) || ( up && y_lim > y_lim_def ) y_lim_def = y_lim end end end if x_lim_def != x_aim @speed . x = 0 if lf ; @x = x_lim_def else ; @x = x_lim_def - @w end end if y_lim_def != y_aim @speed . y = 0 if up ; @y = y_lim_def else ; @y = y_lim_def - @h end end end end @x += @speed . x @y += @speed . y # Keeping contact with ramp # if @speed.y == 0 and @speed.x.abs <= G.ramp_contact_threshold and @bottom.is_a? Ramp #   @y = @bottom.get_y(self) #   puts 'aqui' # end ramps . each do | r | r . check_intersection self end check_contact obst , ramps end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Moves this object as an elevator ( i . e . potentially carrying other objects ) with the specified forces or towards a given point . [CODESPLIT] def move_carrying ( arg , speed , obstacles , obst_obstacles , obst_ramps ) if speed x_d = arg . x - @x ; y_d = arg . y - @y distance = Math . sqrt ( x_d ** 2 + y_d ** 2 ) if distance == 0 @speed . x = @speed . y = 0 return end @speed . x = 1.0 * x_d * speed / distance @speed . y = 1.0 * y_d * speed / distance else arg += G . gravity @speed . x += arg . x / @mass ; @speed . y += arg . y / @mass @speed . x = 0 if @speed . x . abs < G . min_speed . x @speed . y = 0 if @speed . y . abs < G . min_speed . y @speed . x = ( @speed . x <=> 0 ) * @max_speed . x if @speed . x . abs > @max_speed . x @speed . y = ( @speed . y <=> 0 ) * @max_speed . y if @speed . y . abs > @max_speed . y end x_aim = @x + @speed . x ; y_aim = @y + @speed . y passengers = [ ] obstacles . each do | o | if @x + @w > o . x && o . x + o . w > @x foot = o . y + o . h if foot . round ( 6 ) == @y . round ( 6 ) || @speed . y < 0 && foot < @y && foot > y_aim passengers << o end end end prev_x = @x ; prev_y = @y if speed if @speed . x > 0 && x_aim >= arg . x || @speed . x < 0 && x_aim <= arg . x @x = arg . x ; @speed . x = 0 else @x = x_aim end if @speed . y > 0 && y_aim >= arg . y || @speed . y < 0 && y_aim <= arg . y @y = arg . y ; @speed . y = 0 else @y = y_aim end else @x = x_aim ; @y = y_aim end forces = Vector . new @x - prev_x , @y - prev_y prev_g = G . gravity . clone G . gravity . x = G . gravity . y = 0 passengers . each do | p | prev_speed = p . speed . clone prev_forces = p . stored_forces . clone prev_bottom = p . bottom p . speed . x = p . speed . y = 0 p . stored_forces . x = p . stored_forces . y = 0 p . instance_exec { @bottom = nil } p . move forces * p . mass , obst_obstacles , obst_ramps p . speed . x = prev_speed . x p . speed . y = prev_speed . y p . stored_forces . x = prev_forces . x p . stored_forces . y = prev_forces . y p . instance_exec ( prev_bottom ) { | b | @bottom = b } end G . gravity = prev_g end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Moves this object without performing any collision checking towards a specified point or in a specified direction . [CODESPLIT] def move_free ( aim , speed ) if aim . is_a? Vector x_d = aim . x - @x ; y_d = aim . y - @y distance = Math . sqrt ( x_d ** 2 + y_d ** 2 ) if distance == 0 @speed . x = @speed . y = 0 return end @speed . x = 1.0 * x_d * speed / distance @speed . y = 1.0 * y_d * speed / distance if ( @speed . x < 0 and @x + @speed . x <= aim . x ) or ( @speed . x >= 0 and @x + @speed . x >= aim . x ) @x = aim . x @speed . x = 0 else @x += @speed . x end if ( @speed . y < 0 and @y + @speed . y <= aim . y ) or ( @speed . y >= 0 and @y + @speed . y >= aim . y ) @y = aim . y @speed . y = 0 else @y += @speed . y end else rads = aim * Math :: PI / 180 @speed . x = speed * Math . cos ( rads ) @speed . y = speed * Math . sin ( rads ) @x += @speed . x @y += @speed . y end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Causes the object to move in cycles across multiple given points ( the first point in the array is the first point the object will move towards so it doesn t need to be equal to the current / initial position ) . If obstacles are provided it will behave as an elevator ( as in + move_carrying + ) . [CODESPLIT] def cycle ( points , speed , obstacles = nil , obst_obstacles = nil , obst_ramps = nil ) @cur_point = 0 if @cur_point . nil? if obstacles move_carrying points [ @cur_point ] , speed , obstacles , obst_obstacles , obst_ramps else move_free points [ @cur_point ] , speed end if @speed . x == 0 and @speed . y == 0 if @cur_point == points . length - 1 ; @cur_point = 0 else ; @cur_point += 1 ; end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Creates a new ramp . [CODESPLIT] def contact? ( obj ) obj . x + obj . w > @x && obj . x < @x + @w && obj . x . round ( 6 ) == get_x ( obj ) . round ( 6 ) && obj . y . round ( 6 ) == get_y ( obj ) . round ( 6 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if an object is intersecting this ramp ( inside the corresponding right triangle and at the floor level or above ) . [CODESPLIT] def intersect? ( obj ) obj . x + obj . w > @x && obj . x < @x + @w && obj . y > get_y ( obj ) && obj . y <= @y + @h - obj . h end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def check_can_collide ( m ) y = get_y ( m ) + m . h @can_collide = m . x + m . w > @x && @x + @w > m . x && m . y < y && m . y + m . h > y end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new map . [CODESPLIT] def get_absolute_size return Vector . new ( @tile_size . x * @size . x , @tile_size . y * @size . y ) unless @isometric avg = ( @size . x + @size . y ) * 0.5 Vector . new ( avg * @tile_size . x ) . to_i , ( avg * @tile_size . y ) . to_i end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the position in the screen corresponding to the given tile indices . [CODESPLIT] def get_screen_pos ( map_x , map_y ) return Vector . new ( map_x * @tile_size . x - @cam . x , map_y * @tile_size . y - @cam . y ) unless @isometric Vector . new ( ( map_x - map_y - 1 ) * @tile_size . x * 0.5 ) - @cam . x + @x_offset , ( ( map_x + map_y ) * @tile_size . y * 0.5 ) - @cam . y end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the tile in the map that corresponds to the given position in the screen as a Vector where x is the horizontal index and y the vertical index . [CODESPLIT] def get_map_pos ( scr_x , scr_y ) return Vector . new ( ( scr_x + @cam . x ) / @tile_size . x , ( scr_y + @cam . y ) / @tile_size . y ) unless @isometric # Gets the position transformed to isometric coordinates v = get_isometric_position scr_x , scr_y # divides by the square size to find the position in the matrix Vector . new ( ( v . x * @inverse_square_size ) . to_i , ( v . y * @inverse_square_size ) . to_i ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Verifies whether a tile is inside the map . [CODESPLIT] def is_in_map ( v ) v . x >= 0 && v . y >= 0 && v . x < @size . x && v . y < @size . y end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates through the currently visible tiles providing the horizontal tile index the vertical tile index the x - coordinate ( in pixels ) and the y - coordinate ( in pixels ) of each tile in that order to a given block of code . [CODESPLIT] def foreach for j in @min_vis_y .. @max_vis_y for i in @min_vis_x .. @max_vis_x pos = get_screen_pos i , j yield i , j , pos . x , pos . y end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Causes the sprite to animate through the + indices + array exactly once so that the animation stops once it reaches the last index in the array . Subsequent calls with the same parameters will have no effect but if the index or interval changes or if + set_animation + is called then a new animation cycle will begin . [CODESPLIT] def animate_once ( indices , interval ) if @animate_once_control == 2 return if indices == @animate_once_indices && interval == @animate_once_interval @animate_once_control = 0 end unless @animate_once_control == 1 @anim_counter = 0 @img_index = indices [ 0 ] @index_index = 0 @animate_once_indices = indices @animate_once_interval = interval @animate_once_control = 1 return end @anim_counter += 1 return unless @anim_counter >= interval @index_index += 1 @img_index = indices [ @index_index ] @anim_counter = 0 @animate_once_control = 2 if @index_index == indices . length - 1 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the sprite in the screen [CODESPLIT] def draw ( map = nil , scale_x = 1 , scale_y = 1 , alpha = 0xff , color = 0xffffff , angle = nil , flip = nil , z_index = 0 , round = false ) if map . is_a? Hash scale_x = map . fetch ( :scale_x , 1 ) scale_y = map . fetch ( :scale_y , 1 ) alpha = map . fetch ( :alpha , 0xff ) color = map . fetch ( :color , 0xffffff ) angle = map . fetch ( :angle , nil ) flip = map . fetch ( :flip , nil ) z_index = map . fetch ( :z_index , 0 ) round = map . fetch ( :round , false ) map = map . fetch ( :map , nil ) end color = ( alpha << 24 ) | color if angle @img [ @img_index ] . draw_rot @x - ( map ? map . cam . x : 0 ) + @img [ 0 ] . width * scale_x * 0.5 , @y - ( map ? map . cam . y : 0 ) + @img [ 0 ] . height * scale_y * 0.5 , z_index , angle , 0.5 , 0.5 , ( flip == :horiz ? - scale_x : scale_x ) , ( flip == :vert ? - scale_y : scale_y ) , color else x = @x - ( map ? map . cam . x : 0 ) + ( flip == :horiz ? scale_x * @img [ 0 ] . width : 0 ) y = @y - ( map ? map . cam . y : 0 ) + ( flip == :vert ? scale_y * @img [ 0 ] . height : 0 ) @img [ @img_index ] . draw ( round ? x . round : x ) , ( round ? y . round : y ) , z_index , ( flip == :horiz ? - scale_x : scale_x ) , ( flip == :vert ? - scale_y : scale_y ) , color end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns whether this sprite is visible in the given map ( i . e . in the viewport determined by the camera of the given map ) . If no map is given returns whether the sprite is visible on the screen . [CODESPLIT] def visible? ( map = nil ) r = Rectangle . new @x , @y , @img [ 0 ] . width , @img [ 0 ] . height return Rectangle . new ( 0 , 0 , G . window . width , G . window . height ) . intersect? r if map . nil? map . cam . intersect? r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a component to this panel . Parameters : [ c ] The component to add . [CODESPLIT] def add_component ( c ) _ , x , y = FormUtils . check_anchor ( c . anchor , c . anchor_offset_x , c . anchor_offset_y , c . w , c . h , @w , @h ) c . set_position ( @x + x , @y + y ) @controls << c end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the panel and all its child components . Parameters : [ alpha ] The opacity of the panel ( 0 = fully transparent 255 = fully opaque ) . [ z_index ] The z - index to draw the panel . [ color ] The color to apply as filter to the panel image and to all child components images as well . [CODESPLIT] def draw ( alpha = 255 , z_index = 0 , color = 0xffffff ) return unless @visible c = ( alpha << 24 ) | color if @img if @img . is_a? ( Array ) @img [ 0 ] . draw ( @x , @y , z_index , @scale_x , @scale_y , c ) @img [ 1 ] . draw ( @x + @tile_w , @y , z_index , @center_scale_x , @scale_y , c ) if @draw_center_x @img [ 2 ] . draw ( @x + @w - @tile_w , @y , z_index , @scale_x , @scale_y , c ) @img [ 3 ] . draw ( @x , @y + @tile_h , z_index , @scale_x , @center_scale_y , c ) if @draw_center_y @img [ 4 ] . draw ( @x + @tile_w , @y + @tile_h , z_index , @center_scale_x , @center_scale_y , c ) if @draw_center_x && @draw_center_y @img [ 5 ] . draw ( @x + @w - @tile_w , @y + @tile_h , z_index , @scale_x , @center_scale_y , c ) if @draw_center_y @img [ 6 ] . draw ( @x , @y + @h - @tile_h , z_index , @scale_x , @scale_y , c ) @img [ 7 ] . draw ( @x + @tile_w , @y + @h - @tile_h , z_index , @center_scale_x , @scale_y , c ) if @draw_center_x @img [ 8 ] . draw ( @x + @w - @tile_w , @y + @h - @tile_h , z_index , @scale_x , @scale_y , c ) else @img . draw ( @x , @y , z_index , @w . to_f / @img . width , @h . to_f / @img . height ) end end @controls . each { | k | k . draw ( alpha , z_index , color ) if k . visible } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a button . [CODESPLIT] def update return unless @enabled and @visible mouse_over = Mouse . over? @x , @y , @w , @h mouse_press = Mouse . button_pressed? :left mouse_rel = Mouse . button_released? :left if @state == :up if mouse_over @img_index = 1 @state = :over else @img_index = 0 end elsif @state == :over if not mouse_over @img_index = 0 @state = :up elsif mouse_press @img_index = 2 @state = :down else @img_index = 1 end elsif @state == :down if not mouse_over @img_index = 0 @state = :down_out elsif mouse_rel @img_index = 1 @state = :over click else @img_index = 2 end else # :down_out if mouse_over @img_index = 2 @state = :down elsif mouse_rel @img_index = 0 @state = :up else @img_index = 0 end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the button in the screen . [CODESPLIT] def draw ( alpha = 0xff , z_index = 0 , color = 0xffffff ) return unless @visible color = ( alpha << 24 ) | color text_color = if @enabled if @state == :down @down_text_color else @state == :over ? @over_text_color : @text_color end else @disabled_text_color end text_color = ( alpha << 24 ) | text_color @img [ @img_index ] . draw @x , @y , z_index , @scale_x , @scale_y , color if @img if @text if @center_x or @center_y rel_x = @center_x ? 0.5 : 0 rel_y = @center_y ? 0.5 : 0 @font . draw_text_rel @text , @text_x , @text_y , z_index , rel_x , rel_y , @scale_x , @scale_y , text_color else @font . draw_text @text , @text_x , @text_y , z_index , @scale_x , @scale_y , text_color end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new text field . [CODESPLIT] def update return unless @enabled and @visible ################################ Mouse ################################ if Mouse . over? @x , @y , @w , @h if not @active and Mouse . button_pressed? :left focus end elsif Mouse . button_pressed? :left unfocus end return unless @active if Mouse . double_click? :left if @nodes . size > 1 @anchor1 = 0 @anchor2 = @nodes . size - 1 @cur_node = @anchor2 @double_clicked = true end set_cursor_visible elsif Mouse . button_pressed? :left set_node_by_mouse @anchor1 = @cur_node @anchor2 = nil @double_clicked = false set_cursor_visible elsif Mouse . button_down? :left if @anchor1 and not @double_clicked set_node_by_mouse if @cur_node != @anchor1 ; @anchor2 = @cur_node else ; @anchor2 = nil ; end set_cursor_visible end elsif Mouse . button_released? :left if @anchor1 and not @double_clicked if @cur_node != @anchor1 ; @anchor2 = @cur_node else ; @anchor1 = nil ; end end end @cursor_timer += 1 if @cursor_timer >= 30 @cursor_visible = ( not @cursor_visible ) @cursor_timer = 0 end ############################### Keyboard ############################## shift = ( KB . key_down? ( @k [ 53 ] ) or KB . key_down? ( @k [ 54 ] ) ) if KB . key_pressed? ( @k [ 53 ] ) or KB . key_pressed? ( @k [ 54 ] ) # shift @anchor1 = @cur_node if @anchor1 . nil? elsif KB . key_released? ( @k [ 53 ] ) or KB . key_released? ( @k [ 54 ] ) @anchor1 = nil if @anchor2 . nil? end inserted = false for i in 0 .. 46 # alnum if KB . key_pressed? ( @k [ i ] ) or KB . key_held? ( @k [ i ] ) remove_interval true if @anchor1 and @anchor2 if i < 26 if shift insert_char @chars [ i + 37 ] else insert_char @chars [ i ] end elsif i < 36 if shift ; insert_char @chars [ i + 59 ] else ; insert_char @chars [ i ] ; end elsif shift insert_char ( @chars [ i + 49 ] ) else insert_char ( @chars [ i - 10 ] ) end inserted = true break end end return if inserted for i in 55 .. 65 # special if KB . key_pressed? ( @k [ i ] ) or KB . key_held? ( @k [ i ] ) remove_interval true if @anchor1 and @anchor2 if shift ; insert_char @chars [ i + 19 ] else ; insert_char @chars [ i + 8 ] ; end inserted = true break end end return if inserted for i in 66 .. 69 # numpad operators if KB . key_pressed? ( @k [ i ] ) or KB . key_held? ( @k [ i ] ) remove_interval true if @anchor1 and @anchor2 insert_char @chars [ i + 19 ] inserted = true break end end return if inserted if KB . key_pressed? ( @k [ 47 ] ) or KB . key_held? ( @k [ 47 ] ) # back if @anchor1 and @anchor2 remove_interval elsif @cur_node > 0 remove_char true end elsif KB . key_pressed? ( @k [ 48 ] ) or KB . key_held? ( @k [ 48 ] ) # del if @anchor1 and @anchor2 remove_interval elsif @cur_node < @nodes . size - 1 remove_char false end elsif KB . key_pressed? ( @k [ 49 ] ) or KB . key_held? ( @k [ 49 ] ) # left if @anchor1 if shift if @cur_node > 0 @cur_node -= 1 @anchor2 = @cur_node set_cursor_visible end elsif @anchor2 @cur_node = @anchor1 < @anchor2 ? @anchor1 : @anchor2 @anchor1 = nil @anchor2 = nil set_cursor_visible end elsif @cur_node > 0 @cur_node -= 1 set_cursor_visible end elsif KB . key_pressed? ( @k [ 50 ] ) or KB . key_held? ( @k [ 50 ] ) # right if @anchor1 if shift if @cur_node < @nodes . size - 1 @cur_node += 1 @anchor2 = @cur_node set_cursor_visible end elsif @anchor2 @cur_node = @anchor1 > @anchor2 ? @anchor1 : @anchor2 @anchor1 = nil @anchor2 = nil set_cursor_visible end elsif @cur_node < @nodes . size - 1 @cur_node += 1 set_cursor_visible end elsif KB . key_pressed? ( @k [ 51 ] ) # home @cur_node = 0 if shift ; @anchor2 = @cur_node else @anchor1 = nil @anchor2 = nil end set_cursor_visible elsif KB . key_pressed? ( @k [ 52 ] ) # end @cur_node = @nodes . size - 1 if shift ; @anchor2 = @cur_node else @anchor1 = nil @anchor2 = nil end set_cursor_visible end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the text of the text field to the specified value . [CODESPLIT] def text = ( value , trigger_changed = true ) @text = value [ 0 ... @max_length ] @nodes . clear ; @nodes << @text_x x = @nodes [ 0 ] @text . chars . each { | char | x += @font . text_width ( char ) * @scale_x @nodes << x } @cur_node = @nodes . size - 1 @anchor1 = nil @anchor2 = nil set_cursor_visible @on_text_changed . call @text , @params if trigger_changed && @on_text_changed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the position of the text field in the screen . [CODESPLIT] def set_position ( x , y ) d_x = x - @x d_y = y - @y @x = x ; @y = y @text_x += d_x @text_y += d_y @nodes . map! do | n | n + d_x end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the text field in the screen . [CODESPLIT] def draw ( alpha = 0xff , z_index = 0 , color = 0xffffff , disabled_color = 0x808080 ) return unless @visible color = ( alpha << 24 ) | ( ( @enabled or @disabled_img ) ? color : disabled_color ) text_color = ( alpha << 24 ) | ( @enabled ? @text_color : @disabled_text_color ) img = ( ( @enabled or @disabled_img . nil? ) ? @img : @disabled_img ) img . draw @x , @y , z_index , @scale_x , @scale_y , color @font . draw_text @text , @text_x , @text_y , z_index , @scale_x , @scale_y , text_color if @anchor1 and @anchor2 selection_color = ( ( alpha / 2 ) << 24 ) | @selection_color G . window . draw_quad @nodes [ @anchor1 ] , @text_y , selection_color , @nodes [ @anchor2 ] + 1 , @text_y , selection_color , @nodes [ @anchor2 ] + 1 , @text_y + @font . height * @scale_y , selection_color , @nodes [ @anchor1 ] , @text_y + @font . height * @scale_y , selection_color , z_index end if @cursor_visible if @cursor_img @cursor_img . draw @nodes [ @cur_node ] - ( @cursor_img . width * @scale_x ) / 2 , @text_y , z_index , @scale_x , @scale_y else cursor_color = alpha << 24 G . window . draw_quad @nodes [ @cur_node ] , @text_y , cursor_color , @nodes [ @cur_node ] + 1 , @text_y , cursor_color , @nodes [ @cur_node ] + 1 , @text_y + @font . height * @scale_y , cursor_color , @nodes [ @cur_node ] , @text_y + @font . height * @scale_y , cursor_color , z_index end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the progress bar . [CODESPLIT] def draw ( alpha = 0xff , z_index = 0 , color = 0xffffff ) return unless @visible if @bg c = ( alpha << 24 ) | color @bg . draw @x , @y , z_index , @scale_x , @scale_y , c else c = ( alpha << 24 ) | @bg_color G . window . draw_quad @x , @y , c , @x + @w , @y , c , @x + @w , @y + @h , c , @x , @y + @h , c , z_index end if @fg c = ( alpha << 24 ) | color w1 = @fg . width * @scale_x w2 = ( @value . to_f / @max_value * @w ) . round x0 = @x + @fg_margin_x x = 0 while x <= w2 - w1 @fg . draw x0 + x , @y + @fg_margin_y , z_index , @scale_x , @scale_y , c x += w1 end if w2 - x > 0 img = Gosu :: Image . new ( @fg_path , tileable : true , retro : @retro , rect : [ 0 , 0 , ( ( w2 - x ) / @scale_x ) . round , @fg . height ] ) img . draw x0 + x , @y + @fg_margin_y , z_index , @scale_x , @scale_y , c end else c = ( alpha << 24 ) | @fg_color rect_r = @x + ( @value . to_f / @max_value * @w ) . round G . window . draw_quad @x , @y , c , rect_r , @y , c , rect_r , @y + @h , c , @x , @y + @h , c , z_index end if @font c = ( alpha << 24 ) | @text_color @text = @format == '%' ? \"#{(@value.to_f / @max_value * 100).round}%\" : \"#{@value}/#{@max_value}\" @font . draw_text_rel @text , @x + @w / 2 , @y + @h / 2 , z_index , 0.5 , 0.5 , @scale_x , @scale_y , c end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new drop - down list . [CODESPLIT] def update return unless @enabled and @visible if @open and Mouse . button_pressed? :left and not Mouse . over? ( @x , @y , @w , @max_h ) toggle return end @buttons . each { | b | b . update } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the currently selected value of the drop - down list . It is ignored if it is not among the available options . [CODESPLIT] def value = ( val ) if @options . include? val old = @value @value = @buttons [ 0 ] . text = val @on_changed . call ( old , val ) if @on_changed end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the drop - down list . [CODESPLIT] def draw ( alpha = 0xff , z_index = 0 , color = 0xffffff , over_color = 0xcccccc ) return unless @visible unless @img bottom = @y + ( @open ? @max_h : @h ) + @scale_y b_color = ( alpha << 24 ) G . window . draw_quad @x - @scale_x , @y - @scale_y , b_color , @x + @w + @scale_x , @y - @scale_y , b_color , @x + @w + @scale_x , bottom , b_color , @x - @scale_x , bottom , b_color , z_index @buttons . each do | b | c = ( alpha << 24 ) | ( b . state == :over ? over_color : color ) G . window . draw_quad b . x , b . y , c , b . x + b . w , b . y , c , b . x + b . w , b . y + b . h , c , b . x , b . y + b . h , c , z_index + 1 if b . visible end end @buttons [ 0 ] . draw ( alpha , z_index , color ) @buttons [ 1 .. - 1 ] . each { | b | b . draw alpha , z_index + 1 , color } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new label . [CODESPLIT] def draw ( alpha = 255 , z_index = 0 , color = 0xffffff ) c = @enabled ? @text_color : @disabled_text_color r1 = c >> 16 g1 = ( c & 0xff00 ) >> 8 b1 = ( c & 0xff ) r2 = color >> 16 g2 = ( color & 0xff00 ) >> 8 b2 = ( color & 0xff ) r1 *= r2 ; r1 /= 255 g1 *= g2 ; g1 /= 255 b1 *= b2 ; b1 /= 255 color = ( alpha << 24 ) | ( r1 << 16 ) | ( g1 << 8 ) | b1 @font . draw_text ( @text , @x , @y , z_index , @scale_x , @scale_y , color ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a TextHelper . [CODESPLIT] def write_line ( text , x = nil , y = nil , mode = :left , color = 0 , alpha = 0xff , effect = nil , effect_color = 0 , effect_size = 1 , effect_alpha = 0xff , z_index = 0 ) if text . is_a? Hash x = text [ :x ] y = text [ :y ] mode = text . fetch ( :mode , :left ) color = text . fetch ( :color , 0 ) alpha = text . fetch ( :alpha , 0xff ) effect = text . fetch ( :effect , nil ) effect_color = text . fetch ( :effect_color , 0 ) effect_size = text . fetch ( :effect_size , 1 ) effect_alpha = text . fetch ( :effect_alpha , 0xff ) z_index = text . fetch ( :z_index , 0 ) text = text [ :text ] end color = ( alpha << 24 ) | color rel = case mode when :left then 0 when :center then 0.5 when :right then 1 else 0 end if effect effect_color = ( effect_alpha << 24 ) | effect_color if effect == :border @font . draw_markup_rel text , x - effect_size , y - effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x , y - effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x + effect_size , y - effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x + effect_size , y , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x + effect_size , y + effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x , y + effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x - effect_size , y + effect_size , z_index , rel , 0 , 1 , 1 , effect_color @font . draw_markup_rel text , x - effect_size , y , z_index , rel , 0 , 1 , 1 , effect_color elsif effect == :shadow @font . draw_markup_rel text , x + effect_size , y + effect_size , z_index , rel , 0 , 1 , 1 , effect_color end end @font . draw_markup_rel text , x , y , z_index , rel , 0 , 1 , 1 , color end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws text breaking lines when needed and when explicitly caused by the \\ n character . [CODESPLIT] def write_breaking ( text , x , y , width , mode = :left , color = 0 , alpha = 0xff , z_index = 0 ) color = ( alpha << 24 ) | color text . split ( \"\\n\" ) . each do | p | if mode == :justified y = write_paragraph_justified p , x , y , width , color , z_index else rel = case mode when :left then 0 when :center then 0.5 when :right then 1 else 0 end y = write_paragraph p , x , y , width , rel , color , z_index end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a new GlobalFitMessage to the mapper and return the local message number . [CODESPLIT] def add_global ( message ) unless ( slot = @entries . index { | e | e . nil? } ) # No more free slots. We have to find the least recently used one. slot = 0 0 . upto ( 15 ) do | i | if i != slot && @entries [ slot ] . last_use > @entries [ i ] . last_use slot = i end end end @entries [ slot ] = Entry . new ( message , Time . now ) slot end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the local message number for a given GlobalFitMessage . If there is no message number nil is returned . [CODESPLIT] def get_local ( message ) 0 . upto ( 15 ) do | i | if ( entry = @entries [ i ] ) && entry . global_message == message entry . last_use = Time . now return i end end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Monitoring_B object . [CODESPLIT] def check last_timestamp = ts_16_offset = nil last_ts_16 = nil # The timestamp_16 is a 2 byte time stamp value that is used instead of # the 4 byte timestamp field for monitoring records that have # current_activity_type_intensity values with an activity type of 6. The # value seems to be in seconds, but the 0 value reference does not seem # to be included in the file. However, it can be approximated using the # surrounding timestamp values. @monitorings . each do | record | if last_ts_16 && ts_16_offset && record . timestamp_16 && record . timestamp_16 < last_ts_16 # Detect timestamp_16 wrap-arounds. timestamp_16 is a 16 bit value. # In case of a wrap-around we adjust the ts_16_offset accordingly. ts_16_offset += 2 ** 16 end if ts_16_offset # We have already found the offset. Adjust all timestamps according # to 'offset + timestamp_16' if record . timestamp_16 record . timestamp = ts_16_offset + record . timestamp_16 last_ts_16 = record . timestamp_16 end else # We are still looking for the offset. if record . timestamp_16 && last_timestamp # We have a previous timestamp and found the first record with a # timestamp_16 value set. We assume that the timestamp of this # record is one minute after the previously found timestamp. # That's just a guess. Who knows what the Garmin engineers were # thinking here? ts_16_offset = last_timestamp + 60 - record . timestamp_16 record . timestamp = ts_16_offset + record . timestamp_16 last_ts_16 = record . timestamp_16 else # Just save the timestamp of the current record. last_timestamp = record . timestamp end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new FitDataRecord . [CODESPLIT] def new_fit_data_record ( record_type , field_values = { } ) case record_type when 'file_id' @file_id = ( record = FileId . new ( field_values ) ) when 'software' @software = ( record = Software . new ( field_values ) ) when 'device_info' @device_infos << ( record = DeviceInfo . new ( field_values ) ) when 'monitoring_info' @monitoring_infos << ( record = MonitoringInfo . new ( field_values ) ) when 'monitoring' @monitorings << ( record = Monitoring . new ( field_values ) ) else record = nil end record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new FieldDescription object . [CODESPLIT] def create_global_definition ( fit_entity ) messages = fit_entity . developer_fit_messages unless ( gfm = GlobalFitMessages [ @native_mesg_num ] ) Log . error \"Developer field description references unknown global \" + \"message number #{@native_mesg_num}\" return end if @developer_data_index >= fit_entity . top_level_record . developer_data_ids . size Log . error \"Developer data index #{@developer_data_index} is too large\" return end msg = messages [ @native_mesg_num ] || messages . message ( @native_mesg_num , gfm . name ) unless ( @fit_base_type_id & 0x7F ) < FIT_TYPE_DEFS . size Log . error \"fit_base_type_id #{@fit_base_type_id} is too large\" return end options = { } options [ :scale ] = @scale if @scale options [ :offset ] = @offset if @offset options [ :array ] = @array if @array options [ :unit ] = @units msg . field ( @field_definition_number , FIT_TYPE_DEFS [ @fit_base_type_id & 0x7F ] [ 1 ] , \"_#{@developer_data_index}_#{@field_name}\" , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that FitDataRecords have a deterministic sequence . Device infos are sorted by device_index . [CODESPLIT] def check ( index ) unless @device_index Log . fatal 'device info record must have a device_index' end if @device_index == 0 unless @manufacturer Log . fatal 'device info record 0 must have a manufacturer field set' end if @manufacturer == 'garmin' unless @garmin_product Log . fatal 'device info record 0 must have a garman_product ' + 'field set' end else unless @product Log . fatal 'device info record 0 must have a product field set' end end if @serial_number . nil? Log . fatal 'device info record 0 must have a serial number set' end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Redirect all log messages to the given IO . [CODESPLIT] def open ( io ) begin @@logger = Logger . new ( io ) rescue => e @@logger = Logger . new ( $stderr ) Log . fatal \"Cannot open log file: #{e.message}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new FitDataRecord . [CODESPLIT] def new_fit_data_record ( record_type , field_values = { } ) case record_type when 'file_id' @file_id = ( record = FileId . new ( field_values ) ) when 'file_creator' @software = ( record = FileCreator . new ( field_values ) ) when 'device_info' @device_infos << ( record = DeviceInfo . new ( field_values ) ) when 'training_status' @training_statuses << ( record = TrainingStatus . new ( field_values ) ) else record = nil end record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a FitFileEntity . Set what kind of FIT file we are dealing with . [CODESPLIT] def set_type ( type ) if @top_level_record Log . fatal \"FIT file type has already been set to \" + \"#{@top_level_record.class}\" end case type when 4 , 'activity' @top_level_record = Activity . new @type = 'activity' when 32 , 'monitoring_b' @top_level_record = Monitoring_B . new @type = 'monitoring_b' when 44 , 'metrics' @top_level_record = Metrics . new @type = 'metrics' else Log . error \"Unsupported FIT file type #{type}\" return nil end @top_level_record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Activity object . [CODESPLIT] def check unless @timestamp && @timestamp >= Time . parse ( '1990-01-01T00:00:00+00:00' ) Log . fatal \"Activity has no valid timestamp\" end unless @total_timer_time Log . fatal \"Activity has no valid total_timer_time\" end unless @device_infos . length > 0 Log . fatal \"Activity must have at least one device_info section\" end @device_infos . each . with_index { | d , index | d . check ( index ) } @sensor_settings . each . with_index { | s , index | s . check ( index ) } unless @num_sessions == @sessions . count Log . fatal \"Activity record requires #{@num_sessions}, but \" \"#{@sessions.length} session records were found in the \" \"FIT file.\" end # Records must have consecutively growing timestamps and distances. ts = Time . parse ( '1989-12-31' ) distance = nil invalid_records = [ ] @records . each_with_index do | r , idx | Log . fatal \"Record has no timestamp\" unless r . timestamp if r . timestamp < ts Log . fatal \"Record has earlier timestamp than previous record\" end if r . distance if distance && r . distance < distance # Normally this should be a fatal error as the FIT file is clearly # broken. Unfortunately, the Skiing/Boarding app in the Fenix3 # produces such broken FIT files. So we just warn about this # problem and discard the earlier records. Log . error \"Record #{r.timestamp} has smaller distance \" + \"(#{r.distance}) than an earlier record (#{distance}).\" # Index of the list record to be discarded. ( idx - 1 ) . downto ( 0 ) do | i | if ( ri = @records [ i ] ) . distance > r . distance # This is just an approximation. It looks like the app adds # records to the FIT file for runs that it meant to discard. # Maybe the two successive time start events are a better # criteria. But this workaround works for now. invalid_records << ri else # All broken records have been found. break end end end distance = r . distance end ts = r . timestamp end unless invalid_records . empty? # Delete all the broken records from the @records Array. Log . warn \"Discarding #{invalid_records.length} earlier records\" @records . delete_if { | r | invalid_records . include? ( r ) } end # Laps must have a consecutively growing message index. @laps . each . with_index do | lap , index | lap . check ( index ) # If we have heart rate zone records, there should be one for each # lap @heart_rate_zones [ index ] . check ( index ) if @heart_rate_zones [ index ] end @sessions . each { | s | s . check ( self ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Total distance convered by this activity purely computed by the GPS coordinates . This may differ from the distance computed by the device as it can be based on a purely calibrated footpod . [CODESPLIT] def total_gps_distance timer_stops = [ ] # Generate a list of all timestamps where the timer was stopped. @events . each do | e | if e . event == 'timer' && e . event_type == 'stop_all' timer_stops << e . timestamp end end # The first record of a FIT file can already have a distance associated # with it. The GPS location of the first record is not where the start # button was pressed. This introduces a slight inaccurcy when computing # the total distance purely on the GPS coordinates found in the records. d = 0.0 last_lat = last_long = nil last_timestamp = nil # Iterate over all the records and accumlate the distances between the # neiboring coordinates. @records . each do | r | if ( lat = r . position_lat ) && ( long = r . position_long ) if last_lat && last_long distance = Fit4Ruby :: GeoMath . distance ( last_lat , last_long , lat , long ) d += distance end if last_timestamp speed = distance / ( r . timestamp - last_timestamp ) end if timer_stops [ 0 ] == r . timestamp # If a stop event was found for this record timestamp we clear the # last_* values so that the distance covered while being stopped # is not added to the total. last_lat = last_long = nil last_timestamp = nil timer_stops . shift else last_lat = lat last_long = long last_timestamp = r . timestamp end end end d end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the computed VO2max value . This value is computed by the device based on multiple previous activities . [CODESPLIT] def vo2max # First check the event log for a vo2max reporting event. @events . each do | e | return e . vo2max if e . event == 'vo2max' end # Then check the user_data entries for a metmax entry. METmax * 3.5 # is same value as VO2max. @user_data . each do | u | return u . metmax * 3.5 if u . metmax end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the Activity data to a file . [CODESPLIT] def write ( io , id_mapper ) @file_id . write ( io , id_mapper ) @file_creator . write ( io , id_mapper ) ( @field_descriptions + @developer_data_ids + @device_infos + @sensor_settings + @data_sources + @user_profiles + @physiological_metrics + @events + @sessions + @laps + @records + @heart_rate_zones + @personal_records ) . sort . each do | s | s . write ( io , id_mapper ) end super end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if the current Activity is equal to the passed Activity . [CODESPLIT] def new_fit_data_record ( record_type , field_values = { } ) case record_type when 'file_id' @file_id = ( record = FileId . new ( field_values ) ) when 'field_description' @field_descriptions << ( record = FieldDescription . new ( field_values ) ) when 'developer_data_id' @developer_data_ids << ( record = DeveloperDataId . new ( field_values ) ) when 'epo_data' @epo_data = ( record = EPO_Data . new ( field_values ) ) when 'file_creator' @file_creator = ( record = FileCreator . new ( field_values ) ) when 'device_info' @device_infos << ( record = DeviceInfo . new ( field_values ) ) when 'sensor_settings' @sensor_settings << ( record = SensorSettings . new ( field_values ) ) when 'data_sources' @data_sources << ( record = DataSources . new ( field_values ) ) when 'user_data' @user_data << ( record = UserData . new ( field_values ) ) when 'user_profile' @user_profiles << ( record = UserProfile . new ( field_values ) ) when 'physiological_metrics' @physiological_metrics << ( record = PhysiologicalMetrics . new ( field_values ) ) when 'event' @events << ( record = Event . new ( field_values ) ) when 'session' unless @cur_lap_records . empty? # Copy selected fields from section to lap. lap_field_values = { } [ :timestamp , :sport ] . each do | f | lap_field_values [ f ] = field_values [ f ] if field_values . include? ( f ) end # Ensure that all previous records have been assigned to a lap. record = create_new_lap ( lap_field_values ) end @num_sessions += 1 @sessions << ( record = Session . new ( @cur_session_laps , @lap_counter , field_values ) ) @cur_session_laps = [ ] when 'lap' record = create_new_lap ( field_values ) when 'record' @cur_lap_records << ( record = Record . new ( field_values ) ) @records << record when 'hrv' @hrv << ( record = HRV . new ( field_values ) ) when 'heart_rate_zones' @heart_rate_zones << ( record = HeartRateZones . new ( field_values ) ) when 'personal_records' @personal_records << ( record = PersonalRecords . new ( field_values ) ) else record = nil end record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Session object . [CODESPLIT] def check ( activity ) unless @first_lap_index Log . fatal 'first_lap_index is not set' end unless @num_laps Log . fatal 'num_laps is not set' end @first_lap_index . upto ( @first_lap_index - @num_laps ) do | i | if ( lap = activity . lap [ i ] ) @laps << lap else Log . fatal \"Session references lap #{i} which is not contained in \" \"the FIT file.\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new GlobalFitMessage definition . [CODESPLIT] def field ( number , type , name , opts = { } ) field = Field . new ( type , name , opts ) register_field_by_name ( field , name ) register_field_by_number ( field , number ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Define a new set of Field alternatives for this message definition . [CODESPLIT] def alt_field ( number , ref_field , & block ) unless @fields_by_name . include? ( ref_field ) raise \"Unknown ref_field: #{ref_field}\" end field = AltField . new ( self , ref_field , block ) register_field_by_number ( field , number ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "In development raises an error if the captcha field is not blank . This is is good to remember that the field should be hidden with CSS and shown only to robots . [CODESPLIT] def spam? self . class . mail_captcha . each do | field | next if send ( field ) . blank? if defined? ( Rails ) && Rails . env . development? raise ScriptError , \"The captcha field #{field} was supposed to be blank\" else return true end end false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deliver the resource without running any validation . [CODESPLIT] def deliver! mailer = MailForm :: Notifier . contact ( self ) if mailer . respond_to? ( :deliver_now ) mailer . deliver_now else mailer . deliver end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a hash of attributes according to the attributes existent in self . class . mail_attributes . [CODESPLIT] def mail_form_attributes self . class . mail_attributes . each_with_object ( { } ) do | attr , hash | hash [ attr . to_s ] = send ( attr ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Start Solr and wait for it to become available [CODESPLIT] def start extract_and_configure if config . managed? exec ( 'start' , p : port , c : config . cloud ) # Wait for solr to start unless status sleep config . poll_interval end after_start end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stop Solr and wait for it to finish exiting [CODESPLIT] def restart if config . managed? && started? exec ( 'restart' , p : port , c : config . cloud ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check the status of a managed Solr service [CODESPLIT] def status return true unless config . managed? out = exec ( 'status' ) . read out =~ / #{ port } / rescue false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new collection in solr [CODESPLIT] def create ( options = { } ) options [ :name ] ||= SecureRandom . hex create_options = { p : port } create_options [ :c ] = options [ :name ] if options [ :name ] create_options [ :n ] = options [ :config_name ] if options [ :config_name ] create_options [ :d ] = options [ :dir ] if options [ :dir ] Retriable . retriable do raise \"Not started yet\" unless started? end # short-circuit if we're using persisted data with an existing core/collection return if options [ :persist ] && create_options [ :c ] && client . exists? ( create_options [ :c ] ) exec ( \"create\" , create_options ) options [ :name ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update the collection configuration in zookeeper [CODESPLIT] def upconfig ( options = { } ) options [ :name ] ||= SecureRandom . hex options [ :zkhost ] ||= zkhost upconfig_options = { upconfig : true , n : options [ :name ] } upconfig_options [ :d ] = options [ :dir ] if options [ :dir ] upconfig_options [ :z ] = options [ :zkhost ] if options [ :zkhost ] exec 'zk' , upconfig_options options [ :name ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy the collection configuration from zookeeper to a local directory [CODESPLIT] def downconfig ( options = { } ) options [ :name ] ||= SecureRandom . hex options [ :zkhost ] ||= zkhost downconfig_options = { downconfig : true , n : options [ :name ] } downconfig_options [ :d ] = options [ :dir ] if options [ :dir ] downconfig_options [ :z ] = options [ :zkhost ] if options [ :zkhost ] exec 'zk' , downconfig_options options [ :name ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new collection run the block and then clean up the collection [CODESPLIT] def with_collection ( options = { } ) options = config . collection_options . merge ( options ) return yield if options . empty? name = create ( options ) begin yield name ensure delete name unless options [ :persist ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Clean up any files solr_wrapper may have downloaded [CODESPLIT] def clean! stop remove_instance_dir! FileUtils . remove_entry ( config . download_dir , true ) if File . exist? ( config . download_dir ) FileUtils . remove_entry ( config . tmp_save_dir , true ) if File . exist? config . tmp_save_dir checksum_validator . clean! FileUtils . remove_entry ( config . version_file ) if File . exist? config . version_file end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Lint / RescueException extract a copy of solr to instance_dir Does noting if solr already exists at instance_dir [CODESPLIT] def extract return config . instance_dir if extracted? zip_path = download begin Zip :: File . open ( zip_path ) do | zip_file | # Handle entries one by one zip_file . each do | entry | dest_file = File . join ( config . tmp_save_dir , entry . name ) FileUtils . remove_entry ( dest_file , true ) entry . extract ( dest_file ) end end rescue Exception => e abort \"Unable to unzip #{zip_path} into #{config.tmp_save_dir}: #{e.message}\" end begin FileUtils . remove_dir ( config . instance_dir , true ) FileUtils . cp_r File . join ( config . tmp_save_dir , File . basename ( config . download_url , \".zip\" ) ) , config . instance_dir self . extracted_version = config . version FileUtils . chmod 0755 , config . solr_binary rescue Exception => e abort \"Unable to copy #{config.tmp_save_dir} to #{config.instance_dir}: #{e.message}\" end config . instance_dir ensure FileUtils . remove_entry config . tmp_save_dir if File . exist? config . tmp_save_dir end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run a bin / solr command [CODESPLIT] def exec ( cmd , options = { } ) stringio = StringIO . new # JRuby uses Popen4 command_runner = IO . respond_to? ( :popen4 ) ? Popen4Runner : PopenRunner runner = command_runner . new ( cmd , options , config ) exit_status = runner . run ( stringio ) if exit_status != 0 && cmd != 'status' raise \"Failed to execute solr #{cmd}: #{stringio.read}. Further information may be available in #{instance_dir}/server/logs\" end stringio end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete the underlying C ++ instance after exec returns Otherwise rb_gc_call_finalizer_at_exit () can delete stuff that Qt :: Application still needs for its cleanup . [CODESPLIT] def exec result = method_missing ( :exec ) disable_threading ( ) self . dispose Qt :: Internal . application_terminated = true result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add three methods propertyNames () slotNames () and signalNames () from Qt3 as they are very useful when debugging [CODESPLIT] def propertyNames ( inherits = false ) res = [ ] if inherits for p in 0 ... propertyCount ( ) res . push property ( p ) . name end else for p in propertyOffset ( ) ... propertyCount ( ) res . push property ( p ) . name end end return res end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a list of signals including inherited ones [CODESPLIT] def get_signals all_signals = [ ] current = @klass while current != Qt :: Base meta = Meta [ current . name ] if ! meta . nil? all_signals . concat meta . signals end current = current . superclass end return all_signals end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds another Duration or a Numeric to this Duration . Numeric values are treated as seconds . [CODESPLIT] def + ( other ) if Duration === other Duration . new ( value + other . value , @parts + other . parts ) else Duration . new ( value + other , @parts + [ [ :seconds , other ] ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a new date / time at the end of the quarter . Example : 31st March 30th June 30th September . DateTime objects will have a time set to 23 : 59 : 59 . [CODESPLIT] def end_of_quarter last_quarter_month = [ 3 , 6 , 9 , 12 ] . detect { | m | m >= month } beginning_of_month . change ( :month => last_quarter_month ) . end_of_month end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a new date / time representing the given day in the next week . Week is assumed to start on + start_day + default is + Date . beginning_of_week + or + config . beginning_of_week + when set . DateTime objects have their time set to 0 : 00 . [CODESPLIT] def next_week ( start_day = Date . beginning_of_week ) first_hour { weeks_since ( 1 ) . beginning_of_week . days_since ( days_span ( start_day ) ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a new date / time representing the given day in the previous week . Week is assumed to start on + start_day + default is + Date . beginning_of_week + or + config . beginning_of_week + when set . DateTime objects have their time set to 0 : 00 . [CODESPLIT] def prev_week ( start_day = Date . beginning_of_week ) first_hour { weeks_ago ( 1 ) . beginning_of_week . days_since ( days_span ( start_day ) ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the number of days to the start of the week on the given day . Week is assumed to start on + start_day + default is + Date . beginning_of_week + or + config . beginning_of_week + when set . [CODESPLIT] def days_to_week_start ( start_day = Date . beginning_of_week ) start_day_number = DAYS_INTO_WEEK [ start_day ] current_day_number = wday != 0 ? wday - 1 : 6 ( current_day_number - start_day_number ) % 7 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Formats a + number + into a US phone number ( e . g . ( 555 ) 123 - 9876 ) . You can customize the format in the + options + hash . [CODESPLIT] def number_to_phone ( number , options = { } ) return unless number options = options . symbolize_keys number = number . to_s . strip area_code = options [ :area_code ] delimiter = options [ :delimiter ] || \"-\" extension = options [ :extension ] country_code = options [ :country_code ] if area_code number . gsub! ( / \\d \\d \\d / , \"(\\\\1) \\\\2#{delimiter}\\\\3\" ) else number . gsub! ( / \\d \\d \\d / , \"\\\\1#{delimiter}\\\\2#{delimiter}\\\\3\" ) number . slice! ( 0 , 1 ) if number . start_with? ( delimiter ) && ! delimiter . blank? end str = '' str << \"+#{country_code}#{delimiter}\" unless country_code . blank? str << number str << \" x #{extension}\" unless extension . blank? str end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create progress bar [CODESPLIT] def reset @width = 0 if no_width @render_period = frequency == 0 ? 0 : 1.0 / frequency @current = 0 @last_render_time = Time . now @last_render_width = 0 @done = false @stopped = false @start_at = Time . now @started = false @tokens = { } @meter . clear end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Advance the progress bar [CODESPLIT] def advance ( progress = 1 , tokens = { } ) return if done? synchronize do emit ( :progress , progress ) if progress . respond_to? ( :to_hash ) tokens , progress = progress , 1 end @start_at = Time . now if @current . zero? && ! @started @current += progress @tokens = tokens @meter . sample ( Time . now , progress ) if ! no_width && @current >= total finish && return end now = Time . now return if ( now - @last_render_time ) < @render_period render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterate over collection either yielding computation to block or provided Enumerator . If the bar s total was not set it would be taken from collection . count otherwise previously set total would be used . This allows using the progressbar with infinite lazy or slowly - calculated enumerators . [CODESPLIT] def iterate ( collection , progress = 1 , & block ) update ( total : collection . count * progress ) unless total progress_enum = Enumerator . new do | iter | collection . each do | elem | advance ( progress ) iter . yield ( elem ) end end block_given? ? progress_enum . each ( block ) : progress_enum end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update configuration options for this bar [CODESPLIT] def update ( options = { } ) synchronize do options . each do | name , val | if @configuration . respond_to? ( \"#{name}=\" ) @configuration . public_send ( \"#{name}=\" , val ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render progress to the output [CODESPLIT] def render return if done? if hide_cursor && @last_render_width == 0 && ! ( @current >= total ) write ( TTY :: Cursor . hide ) end if @multibar characters_in = @multibar . line_inset ( self ) update ( inset : self . class . display_columns ( characters_in ) ) end formatted = @formatter . decorate ( self , @format ) @tokens . each do | token , val | formatted = formatted . gsub ( \":#{token}\" , val ) end padded = padout ( formatted ) write ( padded , true ) @last_render_time = Time . now @last_render_width = self . class . display_columns ( formatted ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Move cursor to a row of the current bar if the bar is rendered under a multibar . Otherwise do not move and yield on current row . [CODESPLIT] def move_to_row if @multibar CURSOR_LOCK . synchronize do if @first_render @row = @multibar . next_row yield if block_given? output . print \"\\n\" @first_render = false else lines_up = ( @multibar . rows + 1 ) - @row output . print TTY :: Cursor . save output . print TTY :: Cursor . up ( lines_up ) yield if block_given? output . print TTY :: Cursor . restore end end else yield if block_given? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write out to the output [CODESPLIT] def write ( data , clear_first = false ) return unless tty? # write only to terminal move_to_row do output . print ( TTY :: Cursor . column ( 1 ) ) if clear_first characters_in = @multibar . line_inset ( self ) if @multibar output . print ( \"#{characters_in}#{data}\" ) output . flush end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "End the progress [CODESPLIT] def finish return if done? @current = total unless no_width render clear ? clear_line : write ( \"\\n\" , false ) ensure @meter . clear @done = true # reenable cursor if it is turned off if hide_cursor && @last_render_width != 0 write ( TTY :: Cursor . show , false ) end emit ( :done ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stop and cancel the progress at the current position [CODESPLIT] def stop # reenable cursor if it is turned off if hide_cursor && @last_render_width != 0 write ( TTY :: Cursor . show , false ) end return if done? render clear ? clear_line : write ( \"\\n\" , false ) ensure @meter . clear @stopped = true emit ( :stopped ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Log message above the current progress bar [CODESPLIT] def log ( message ) sanitized_message = message . gsub ( / \\r \\n / , ' ' ) if done? write ( sanitized_message + \"\\n\" , false ) return end sanitized_message = padout ( sanitized_message ) write ( sanitized_message + \"\\n\" , true ) render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pad message out with spaces [CODESPLIT] def padout ( message ) message_length = self . class . display_columns ( message ) if @last_render_width > message_length remaining_width = @last_render_width - message_length message += ' ' * remaining_width end message end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Reschedule the job in the future ( when a job fails ) . Uses an exponential scale depending on the number of failed attempts . [CODESPLIT] def reschedule ( message , backtrace = [ ] , time = nil ) if self . attempts < MAX_ATTEMPTS time ||= Job . db_time_now + ( attempts ** 4 ) + 5 self . attempts += 1 self . run_at = time self . last_error = message + \"\\n\" + backtrace . join ( \"\\n\" ) self . unlock save! else logger . info \"* [JOB] PERMANENTLY removing #{self.name} because of #{attempts} consequetive failures.\" destroy_failed_jobs ? destroy : update_attribute ( :failed_at , Delayed :: Job . db_time_now ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try to run one job . Returns true / false ( work done / work failed ) or nil if job can t be locked . [CODESPLIT] def run_with_lock ( max_run_time , worker_name ) logger . info \"* [JOB] aquiring lock on #{name}\" unless lock_exclusively! ( max_run_time , worker_name ) # We did not get the lock, some other worker process must have logger . warn \"* [JOB] failed to aquire exclusive lock for #{name}\" return nil # no work done end begin runtime = Benchmark . realtime do invoke_job # TODO: raise error if takes longer than max_run_time destroy end # TODO: warn if runtime > max_run_time ? logger . info \"* [JOB] #{name} completed after %.4f\" % runtime return true # did work rescue Exception => e reschedule e . message , e . backtrace log_exception ( e ) return false # work failed end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Lock this job for this worker . Returns true if we have the lock false otherwise . [CODESPLIT] def lock_exclusively! ( max_run_time , worker = worker_name ) now = self . class . db_time_now affected_rows = if locked_by != worker # We don't own this job so we will update the locked_by name and the locked_at self . class . update_all ( [ \"locked_at = ?, locked_by = ?\" , now , worker ] , [ \"id = ? and (locked_at is null or locked_at < ?)\" , id , ( now - max_run_time . to_i ) ] ) else # We already own this job, this may happen if the job queue crashes. # Simply resume and update the locked_at self . class . update_all ( [ \"locked_at = ?\" , now ] , [ \"id = ? and locked_by = ?\" , id , worker ] ) end if affected_rows == 1 self . locked_at = now self . locked_by = worker return true else return false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "loads all of our tracery files into our + files + hash if a file is named default then we load that into + grammar + [CODESPLIT] def setup_tracery dir_path raise \"Provided path not a directory\" unless Dir . exist? ( dir_path ) @grammar = { } Dir . open ( dir_path ) do | dir | dir . each do | file | # skip our current and parent dir next if file =~ / \\. \\. / # read the rule file into the files hash @grammar [ file . split ( '.' ) . first ] = createGrammar ( JSON . parse ( File . read ( \"#{dir_path}/#{file}\" ) ) ) end end # go ahead and makes a default mention-handler #  if we have a reply rule file unless @grammar [ 'reply' ] . nil? on_reply { | bot | bot . reply_with_mentions ( '#default#' , rules : 'reply' ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "a shortcut fuction for expanding text with tracery before posting [CODESPLIT] def expand_and_post ( text , * options ) opts = Hash [ options ] rules = opts . fetch ( :rules , 'default' ) actually_post ( @grammar [ rules ] . flatten ( text ) , ** opts . reject { | k | k == :rules } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Starts a loop that checks for any notifications for the authenticated user running the appropriate stored proc when needed [CODESPLIT] def run_interact @streamer . user do | update | if update . kind_of? Mastodon :: Notification case update . type when 'mention' # this makes it so .content calls strip instead  update . status . class . module_eval { alias_method :content , :strip } if @strip_html store_mention_data update . status @on_reply . call ( self , update . status ) unless @on_reply . nil? when 'reblog' @on_boost . call ( self , update ) unless @on_boost . nil? when 'favourite' @on_fave . call ( self , update ) unless @on_fave . nil? when 'follow' @on_follow . call ( self , update ) unless @on_follow . nil? end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replies to the last mention the bot recieved using the mention s visibility and spoiler with + text + [CODESPLIT] def reply ( text , * options ) options = Hash [ options ] post ( \"@#{@mention_data[:account].acct} #{text}\" , ** @mention_data . merge ( options ) . reject { | k | k == :mentions or k == :account } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replies to the last post and tags everyone who was mentioned ( this function respects #NoBot ) [CODESPLIT] def reply_with_mentions ( text , * options ) # build up a string of all accounts mentioned in the post #  unless that account is our own, or the tagged account #  has #NoBot mentions = @mention_data [ :mentions ] . collect do | m | \"@#{m.acct}\" unless m . acct == @username or no_bot? m . id end . join ' ' reply ( \"#{mentions.strip} #{text}\" , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Starts a loop that checks for mentions from the authenticated user account running a supplied block or if a block is not provided on_reply [CODESPLIT] def run_reply @streamer . user do | update | next unless update . kind_of? Mastodon :: Notification and update . type == 'mention' # this makes it so .content calls strip instead  update . status . class . module_eval { alias_method :content , :strip } if @strip_html store_mention_data update . status if block_given? yield ( self , update . status ) else @on_reply . call ( self , update . status ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stores select data about a post into a hash for later use [CODESPLIT] def store_mention_data ( mention ) @mention_data = { reply_id : mention . id , visibility : mention . visibility , spoiler : mention . spoiler_text , hide_media : mention . sensitive? , mentions : mention . mentions , account : mention . account } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates the stream client [CODESPLIT] def setup_streaming stream_uri = @client . instance ( ) . attributes [ 'urls' ] [ 'streaming_api' ] . gsub ( / / , 'https' ) @streamer = Mastodon :: Streaming :: Client . new ( base_url : stream_uri , bearer_token : ENV [ 'TOKEN' ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds the command and block into the bot to process later also sets up the command regex [CODESPLIT] def add_command cmd , & block @commands . append cmd unless @commands . include? cmd @cmd_hash [ cmd . to_sym ] = block # build up our regex (this regex should be fine, i guess :shrug:) @cmd_regex = / \\A #{ @prefix } #{ @commands . join ( '|' ) } \\b /m end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Starts loop to process any mentions running command procs set up earlier [CODESPLIT] def run_commands @streamer . user do | update | next unless update . kind_of? Mastodon :: Notification and update . type == 'mention' # set up the status to strip html, if needed update . status . class . module_eval { alias_method :content , :strip } if @strip_html store_mention_data update . status # strip our username out of the status post = update . status . content . gsub ( / #{ @username } / , '' ) # see if the post matches our regex, running the stored proc if it does matches = @cmd_regex . match ( post ) unless matches . nil? @cmd_hash [ matches [ :cmd ] . to_sym ] . call ( self , matches [ :data ] . strip , update . status ) else if block_given? yield ( self , update . status ) else @not_found . call ( self , update . status ) unless @not_found . nil? end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse the service name from a path . Look at the last component of the path ignoring some common names . [CODESPLIT] def parse_service_name ( path ) parts = Pathname . new ( path ) . each_filename . to_a . reverse! # Find the last segment not in common segments, fall back to the last segment. parts . find { | seg | ! COMMON_SEGMENTS [ seg ] } || parts . first end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new TCP Client connection [CODESPLIT] def connect start_time = Time . now retries = 0 close # Number of times to try begin connect_to_server ( servers , policy ) logger . info ( message : \"Connected to #{address}\" , duration : ( Time . now - start_time ) * 1000 ) if respond_to? ( :logger ) rescue ConnectionFailure , ConnectionTimeout => exception cause = exception . is_a? ( ConnectionTimeout ) ? exception : exception . cause # Retry-able? if self . class . reconnect_on_errors . include? ( cause . class ) && ( retries < connect_retry_count . to_i ) retries += 1 logger . warn \"#connect Failed to connect to any of #{servers.join(',')}. Sleeping:#{connect_retry_interval}s. Retry: #{retries}\" if respond_to? ( :logger ) sleep ( connect_retry_interval ) retry else message = \"#connect Failed to connect to any of #{servers.join(',')} after #{retries} retries. #{exception.class}: #{exception.message}\" logger . benchmark_error ( message , exception : exception , duration : ( Time . now - start_time ) ) if respond_to? ( :logger ) raise ConnectionFailure . new ( message , address . to_s , cause ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write data to the server [CODESPLIT] def write ( data , timeout = write_timeout ) data = data . to_s if respond_to? ( :logger ) payload = { timeout : timeout } # With trace level also log the sent data payload [ :data ] = data if logger . trace? logger . benchmark_debug ( '#write' , payload : payload ) do payload [ :bytes ] = socket_write ( data , timeout ) end else socket_write ( data , timeout ) end rescue Exception => exc close if close_on_error raise exc end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a response from the server [CODESPLIT] def read ( length , buffer = nil , timeout = read_timeout ) if respond_to? ( :logger ) payload = { bytes : length , timeout : timeout } logger . benchmark_debug ( '#read' , payload : payload ) do data = socket_read ( length , buffer , timeout ) # With trace level also log the received data payload [ :data ] = data if logger . trace? data end else socket_read ( length , buffer , timeout ) end rescue Exception => exc close if close_on_error raise exc end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write and / or receive data with automatic retry on connection failure [CODESPLIT] def retry_on_connection_failure retries = 0 begin connect if closed? yield ( self ) rescue ConnectionFailure => exception exc_str = exception . cause ? \"#{exception.cause.class}: #{exception.cause.message}\" : exception . message # Re-raise exceptions that should not be retried if ! self . class . reconnect_on_errors . include? ( exception . cause . class ) logger . info \"#retry_on_connection_failure not configured to retry: #{exc_str}\" if respond_to? ( :logger ) raise exception elsif retries < @retry_count retries += 1 logger . warn \"#retry_on_connection_failure retry #{retries} due to #{exception.class}: #{exception.message}\" if respond_to? ( :logger ) connect retry end logger . error \"#retry_on_connection_failure Connection failure: #{exception.class}: #{exception.message}. Giving up after #{retries} retries\" if respond_to? ( :logger ) raise ConnectionFailure . new ( \"After #{retries} retries to host '#{server}': #{exc_str}\" , server , exception . cause ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Close the socket only if it is not already closed [CODESPLIT] def close socket . close if socket && ! socket . closed? @socket = nil @address = nil true rescue IOError => exception logger . warn \"IOError when attempting to close socket: #{exception.class}: #{exception.message}\" if respond_to? ( :logger ) false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns whether the connection to the server is alive [CODESPLIT] def alive? return false if socket . nil? || closed? if IO . select ( [ socket ] , nil , nil , 0 ) ! socket . eof? rescue false else true end rescue IOError false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Connect to one of the servers in the list per the current policy Returns [ Socket ] the socket connected to or an Exception [CODESPLIT] def connect_to_server ( servers , policy ) # Iterate over each server address until it successfully connects to a host last_exception = nil Policy :: Base . factory ( policy , servers ) . each do | address | begin return connect_to_address ( address ) rescue ConnectionTimeout , ConnectionFailure => exception last_exception = exception end end # Raise Exception once it has failed to connect to any server last_exception ? raise ( last_exception ) : raise ( ArgumentError , \"No servers supplied to connect to: #{servers.join(',')}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns [ Socket ] connected to supplied address address [ Net :: TCPClient :: Address ] Host name ip address and port of server to connect to Connect to the server at the supplied address Returns the socket connection [CODESPLIT] def connect_to_address ( address ) socket = if proxy_server :: SOCKSSocket . new ( \"#{address.ip_address}:#{address.port}\" , proxy_server ) else :: Socket . new ( Socket :: AF_INET , Socket :: SOCK_STREAM , 0 ) end unless buffered socket . sync = true socket . setsockopt ( Socket :: IPPROTO_TCP , Socket :: TCP_NODELAY , 1 ) end socket . setsockopt ( Socket :: SOL_SOCKET , Socket :: SO_KEEPALIVE , true ) if keepalive socket_connect ( socket , address , connect_timeout ) @socket = ssl ? ssl_connect ( socket , address , ssl_handshake_timeout ) : socket @address = address # Invoke user supplied Block every time a new connection has been established @on_connect . call ( self ) if @on_connect end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Connect to server [CODESPLIT] def socket_connect ( socket , address , timeout ) socket_address = Socket . pack_sockaddr_in ( address . port , address . ip_address ) # Timeout of -1 means wait forever for a connection return socket . connect ( socket_address ) if timeout == - 1 deadline = Time . now . utc + timeout begin non_blocking ( socket , deadline ) { socket . connect_nonblock ( socket_address ) } rescue Errno :: EISCONN # Connection was successful. rescue NonBlockingTimeout raise ConnectionTimeout . new ( \"Timed out after #{timeout} seconds trying to connect to #{address}\" ) rescue SystemCallError , IOError => exception message = \"#connect Connection failure connecting to '#{address.to_s}': #{exception.class}: #{exception.message}\" logger . error message if respond_to? ( :logger ) raise ConnectionFailure . new ( message , address . to_s , exception ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write to the socket [CODESPLIT] def socket_write ( data , timeout ) if timeout < 0 socket . write ( data ) else deadline = Time . now . utc + timeout length = data . bytesize total_count = 0 non_blocking ( socket , deadline ) do loop do begin count = socket . write_nonblock ( data ) rescue Errno :: EWOULDBLOCK retry end total_count += count return total_count if total_count >= length data = data . byteslice ( count .. - 1 ) end end end rescue NonBlockingTimeout logger . warn \"#write Timeout after #{timeout} seconds\" if respond_to? ( :logger ) raise WriteTimeout . new ( \"Timed out after #{timeout} seconds trying to write to #{address}\" ) rescue SystemCallError , IOError => exception message = \"#write Connection failure while writing to '#{address.to_s}': #{exception.class}: #{exception.message}\" logger . error message if respond_to? ( :logger ) raise ConnectionFailure . new ( message , address . to_s , exception ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try connecting to a single server Returns the connected socket [CODESPLIT] def ssl_connect ( socket , address , timeout ) ssl_context = OpenSSL :: SSL :: SSLContext . new ssl_context . set_params ( ssl . is_a? ( Hash ) ? ssl : { } ) ssl_socket = OpenSSL :: SSL :: SSLSocket . new ( socket , ssl_context ) ssl_socket . hostname = address . host_name ssl_socket . sync_close = true begin if timeout == - 1 # Timeout of -1 means wait forever for a connection ssl_socket . connect else deadline = Time . now . utc + timeout begin non_blocking ( socket , deadline ) { ssl_socket . connect_nonblock } rescue Errno :: EISCONN # Connection was successful. rescue NonBlockingTimeout raise ConnectionTimeout . new ( \"SSL handshake Timed out after #{timeout} seconds trying to connect to #{address.to_s}\" ) end end rescue SystemCallError , OpenSSL :: SSL :: SSLError , IOError => exception message = \"#connect SSL handshake failure with '#{address.to_s}': #{exception.class}: #{exception.message}\" logger . error message if respond_to? ( :logger ) raise ConnectionFailure . new ( message , address . to_s , exception ) end # Verify Peer certificate ssl_verify ( ssl_socket , address ) if ssl_context . verify_mode != OpenSSL :: SSL :: VERIFY_NONE ssl_socket end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Raises Net :: TCPClient :: ConnectionFailure if the peer certificate does not match its hostname [CODESPLIT] def ssl_verify ( ssl_socket , address ) unless OpenSSL :: SSL . verify_certificate_identity ( ssl_socket . peer_cert , address . host_name ) domains = extract_domains_from_cert ( ssl_socket . peer_cert ) ssl_socket . close message = \"#connect SSL handshake failed due to a hostname mismatch. Request address was: '#{address.to_s}'\" + \"  Certificate valid for hostnames: #{domains.map { |d| \"'#{d}'\"}.join(',')}\" logger . error message if respond_to? ( :logger ) raise ConnectionFailure . new ( message , address . to_s ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Party Mode! Join all speakers into a single group . [CODESPLIT] def party_mode new_master = nil return nil unless speakers . length > 1 new_master = find_party_master if new_master . nil? party_over speakers . each do | slave | next if slave . uid == new_master . uid slave . join new_master end rescan @topology end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Look for Sonos devices on the network and return the first IP address found [CODESPLIT] def discover result = SSDP :: Consumer . new . search ( service : 'urn:schemas-upnp-org:device:ZonePlayer:1' , first_only : true , timeout : @timeout , filter : lambda { | r | r [ :params ] [ \"ST\" ] . match ( / / ) } ) @first_device_ip = result [ :address ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find all of the Sonos devices on the network [CODESPLIT] def topology self . discover unless @first_device_ip return [ ] unless @first_device_ip doc = Nokogiri :: XML ( open ( \"http://#{@first_device_ip}:#{Sonos::PORT}/status/topology\" ) ) doc . xpath ( '//ZonePlayers/ZonePlayer' ) . map do | node | TopologyNode . new ( node ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find a single resource by the resource id [CODESPLIT] def find ( id ) response = RestClient . get ( \"#{@type.Resource}/#{id}\" ) singular_resource = @type . Resource [ 0 ... - 1 ] if response . body [ singular_resource ] . nil? raise ArgumentError , 'Resource not found' end type . new . from_json ( response . body [ singular_resource ] . to_json ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all resources from a query by paging through data [CODESPLIT] def all list = [ ] page = 1 fetch_all = true if @query . has_key? ( :page ) page = @query [ :page ] fetch_all = false end while true response = RestClient . get ( @type . Resource , @query ) data = response . body [ @type . Resource ] if ! data . empty? data . each { | item | list << @type . new . from_json ( item . to_json ) } if ! fetch_all break else where ( page : page += 1 ) end else break end end return list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "when calling validates it should create the Vali instance already and set [CODESPLIT] def validate ( form ) property = attributes . first # here is the thing: why does AM::UniquenessValidator require a filled-out record to work properly? also, why do we need to set # the class? it would be way easier to pass #validate a hash of attributes and get back an errors hash. # the class for the finder could either be infered from the record or set in the validator instance itself in the call to ::validates. record = form . model_for_property ( property ) record . send ( \"#{property}=\" , form . send ( property ) ) @klass = record . class # this is usually done in the super-sucky #setup method. super ( record ) . tap do | res | form . errors . add ( property , record . errors . first . last ) if record . errors . present? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "DISCUSS : can we achieve that somehow via features in build_inline? [CODESPLIT] def property ( * ) super . tap do | dfn | return dfn unless dfn [ :nested ] _name = dfn [ :name ] dfn [ :nested ] . instance_eval do @_name = _name . singularize . camelize # this adds Form::name for AM::Validations and I18N. def name @_name end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "moved from reform as not applicable to dry [CODESPLIT] def validates ( * args , & block ) validation ( name : :default , inherit : true ) { validates args , block } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Updates the attribute in the given XML block to the value provided . [CODESPLIT] def update_xml ( xml , values ) if array? values . each do | value | wrap ( xml , :always_create => true ) . tap do | node | XML . set_attribute ( node , name , value . to_s ) end end else wrap ( xml ) . tap do | xml | XML . set_attribute ( xml , name , values . to_s ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates the text in the given _xml_ block to the _value_ provided . [CODESPLIT] def update_xml ( xml , value ) wrap ( xml ) . tap do | xml | if content? add ( xml , value ) elsif name? xml . name = value elsif array? value . each do | v | add ( XML . add_node ( xml , name ) , v ) end else add ( XML . add_node ( xml , name ) , value ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates the composed XML object in the given XML block to the value provided . [CODESPLIT] def update_xml ( xml , value ) wrap ( xml ) . tap do | xml | value . each_pair do | k , v | node = XML . add_node ( xml , hash . wrapper ) @key . update_xml ( node , k ) @value . update_xml ( node , v ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates the composed XML object in the given XML block to the value provided . [CODESPLIT] def update_xml ( xml , value ) wrap ( xml ) . tap do | xml | params = { :name => name , :namespace => opts . namespace } if array? value . each do | v | XML . add_child ( xml , v . to_xml ( params ) ) end elsif value . is_a? ( ROXML ) XML . add_child ( xml , value . to_xml ( params ) ) else XML . add_node ( xml , name ) . tap do | node | XML . set_content ( node , value . to_xml ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Returns an XML object representing this object [CODESPLIT] def to_xml ( params = { } ) params . reverse_merge! ( :name => self . class . tag_name , :namespace => self . class . roxml_namespace ) params [ :namespace ] = nil if [ '*' , 'xmlns' ] . include? ( params [ :namespace ] ) XML . new_node ( [ params [ :namespace ] , params [ :name ] ] . compact . join ( ':' ) ) . tap do | root | refs = ( self . roxml_references . present? ? self . roxml_references : self . class . roxml_attrs . map { | attr | attr . to_ref ( self ) } ) refs . each do | ref | value = ref . to_xml ( self ) unless value . nil? ref . update_xml ( root , value ) end end if params [ :namespaces ] params [ :namespaces ] . each { | prefix , url | root . add_namespace_definition ( prefix , url ) } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the payment on interest for an investment based on constant - amount periodic payments and a constant interest rate . [CODESPLIT] def ipmt ( rate , per , nper , pv , fv = 0 , end_or_beginning = 0 ) pmt = self . pmt ( rate , nper , pv , fv , end_or_beginning ) fv = self . fv ( rate , ( per - 1 ) , pmt , pv , end_or_beginning ) * rate temp = end_or_beginning == 1 ? fv / ( 1 + rate ) : fv ( per == 1 && end_or_beginning == 1 ) ? 0.0 : temp end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the number of payment periods for an investment based on constant - amount periodic payments and a constant interest rate . [CODESPLIT] def nper ( rate , pmt , pv , fv = 0 , end_or_beginning = 0 ) z = pmt * ( 1 + rate * end_or_beginning ) / rate temp = Math . log ( ( - fv + z ) / ( pv + z ) ) temp / Math . log ( 1 + rate ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the periodic payment for an annuity investment based on constant - amount periodic payments and a constant interest rate . [CODESPLIT] def pmt ( rate , nper , pv , fv = 0 , end_or_beginning = 0 ) temp = ( 1 + rate ) ** nper fact = ( 1 + rate * end_or_beginning ) * ( temp - 1 ) / rate - ( fv + pv * temp ) / fact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the interest rate of an annuity investment based on constant - amount periodic payments and the assumption of a constant interest rate . [CODESPLIT] def rate ( nper , pmt , pv , fv = 0 , end_or_beginning = 0 , rate_guess = 0.10 ) guess = rate_guess tolerancy = 1e-6 close = false begin temp = newton_iter ( guess , nper , pmt , pv , fv , end_or_beginning ) next_guess = ( guess - temp ) . round ( 20 ) diff = ( next_guess - guess ) . abs close = diff < tolerancy guess = next_guess end while ! close next_guess end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the net present value of an investment based on a series of periodic cash flows and a discount rate . [CODESPLIT] def npv ( discount , cashflows ) total = 0 cashflows . each_with_index do | cashflow , index | total += ( cashflow . to_f / ( 1 + discount . to_f ) ** ( index + 1 ) ) end total end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the internal rate of return on an investment based on a series of periodic cash flows . [CODESPLIT] def irr ( values ) func = Helpers :: IrrHelper . new ( values ) guess = [ func . eps ] nlsolve ( func , guess ) guess [ 0 ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method was borrowed from the NumPy rate formula which was generated by Sage [CODESPLIT] def newton_iter ( r , n , p , x , y , w ) t1 = ( r + 1 ) ** n t2 = ( r + 1 ) ** ( n - 1 ) ( ( y + t1 x + p ( t1 - 1 ) * ( r w + 1 ) / r ) / ( n t2 x - p ( t1 - 1 ) * ( r w + 1 ) / ( r ** 2 ) + n p t2 ( r w + 1 ) / r + p ( t1 - 1 ) * w / r ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Simple mean formula : sum elements and / by length [CODESPLIT] def mean ( numbers_ary ) numbers_ary . inject ( 0 ) { | sum , i | sum + i } . to_f / numbers_ary . size end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Median formula @param numbers_ary [ array ] an array of numbers [CODESPLIT] def median ( numbers_ary ) numbers_ary . sort! len = numbers_ary . length ( numbers_ary [ ( len - 1 ) / 2 ] + numbers_ary [ len / 2 ] ) / 2.0 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helpers and filters . [CODESPLIT] def event_summary ( trim_at = 100 ) summary = @event [ 'check' ] [ 'notification' ] || @event [ 'check' ] [ 'description' ] if summary . nil? source = @event [ 'check' ] [ 'source' ] || @event [ 'client' ] [ 'name' ] event_context = [ source , @event [ 'check' ] [ 'name' ] ] . join ( '/' ) output = @event [ 'check' ] [ 'output' ] . chomp output = output . length > trim_at ? output [ 0 .. trim_at ] + '...' : output summary = [ event_context , output ] . join ( ' : ' ) end summary end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "geckoboard - ruby gem s dataset . find_or_create id attribute e . g . peoplefinder - staging . total_profiles_report [CODESPLIT] def id Rails . application . class . parent_name . underscore + '-' + ( ENV [ 'ENV' ] || Rails . env ) . downcase + '.' + self . class . name . demodulize . underscore end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "= begin # revisit this def apply io if truncate? io . truncate 0 elsif append? io . seek IO :: SEEK_END 0 end end = end [CODESPLIT] def inspect names = NAMES . map { | name | name if ( flags & IOMode . const_get ( name . upcase ) ) != 0 } names . unshift 'rdonly' if ( flags & 0x3 ) == 0 \"#<#{self.class} #{names.compact * '|'}>\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "tries to get a dirent for path . return nil if it doesn t exist ( change it ) [CODESPLIT] def dirent_from_path path dirent = @root path = file . expand_path ( path ) . split ( '/' ) until path . empty? part = path . shift next if part . empty? return nil if dirent . file? return nil unless dirent = dirent / part end dirent end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "load document from file . [CODESPLIT] def load # we always read 512 for the header block. if the block size ends up being different, # what happens to the 109 fat entries. are there more/less entries? @io . rewind header_block = @io . read 512 @header = Header . new header_block # create an empty bbat. @bbat = AllocationTable :: Big . new self bbat_chain = header_block [ Header :: SIZE .. - 1 ] . unpack 'V*' mbat_block = @header . mbat_start @header . num_mbat . times do blocks = @bbat . read ( [ mbat_block ] ) . unpack 'V*' mbat_block = blocks . pop bbat_chain += blocks end # am i using num_bat in the right way? @bbat . load @bbat . read ( bbat_chain [ 0 , @header . num_bat ] ) # get block chain for directories, read it, then split it into chunks and load the # directory entries. semantics changed - used to cut at first dir where dir.type == 0 @dirents = @bbat . read ( @header . dirent_start ) . to_enum ( :each_chunk , Dirent :: SIZE ) . map { | str | Dirent . new self , str } # now reorder from flat into a tree # links are stored in some kind of balanced binary tree # check that everything is visited at least, and at most once # similarly with the blocks of the file. # was thinking of moving this to Dirent.to_tree instead. class << @dirents def to_tree idx = 0 return [ ] if idx == Dirent :: EOT d = self [ idx ] to_tree ( d . child ) . each { | child | d << child } raise FormatError , \"directory #{d.inspect} used twice\" if d . idx d . idx = idx to_tree ( d . prev ) + [ d ] + to_tree ( d . next ) end end @root = @dirents . to_tree . first @dirents . reject! { | d | d . type_id == 0 } # silence this warning by default, its not really important (issue #5). # fairly common one appears to be \"R\" (from office OS X?) which smells # like some kind of UTF16 snafu, but scottwillson also has had some kanji... #Log.warn \"root name was #{@root.name.inspect}\" unless @root.name == 'Root Entry' unused = @dirents . reject ( :idx ) . length Log . warn \"#{unused} unused directories\" if unused > 0 # FIXME i don't currently use @header.num_sbat which i should # hmm. nor do i write it. it means what exactly again? # which mode to use here? @sb_file = RangesIOResizeable . new @bbat , :first_block => @root . first_block , :size => @root . size @sbat = AllocationTable :: Small . new self @sbat . load @bbat . read ( @header . sbat_start ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "the flush method is the main save method . all file contents are always written directly to the file by the RangesIO objects all this method does is write out all the file meta data - dirents allocation tables file header etc . [CODESPLIT] def flush # update root dirent, and flatten dirent tree @root . name = 'Root Entry' @root . first_block = @sb_file . first_block @root . size = @sb_file . size @dirents = @root . flatten # serialize the dirents using the bbat RangesIOResizeable . open @bbat , 'w' , :first_block => @header . dirent_start do | io | io . write @dirents . map { | dirent | dirent . to_s } . join padding = ( io . size / @bbat . block_size . to_f ) . ceil * @bbat . block_size - io . size io . write 0 . chr * padding @header . dirent_start = io . first_block end # serialize the sbat # perhaps the blocks used by the sbat should be marked with BAT? RangesIOResizeable . open @bbat , 'w' , :first_block => @header . sbat_start do | io | io . write @sbat . to_s @header . sbat_start = io . first_block @header . num_sbat = @bbat . chain ( @header . sbat_start ) . length end # create RangesIOResizeable hooked up to the bbat. use that to claim bbat blocks using # truncate. then when its time to write, convert that chain and some chunk of blocks at # the end, into META_BAT blocks. write out the chain, and those meta bat blocks, and its # done. # this is perhaps not good, as we reclaim all bat blocks here, which # may include the sbat we just wrote. FIXME @bbat . map! do | b | b == AllocationTable :: BAT || b == AllocationTable :: META_BAT ? AllocationTable :: AVAIL : b end # currently we use a loop. this could be better, but basically, # the act of writing out the bat, itself requires blocks which get # recorded in the bat. # # i'm sure that there'd be some simpler closed form solution to this. solve # recursive func: # #   num_mbat_blocks = ceil(max((mbat_len - 109) * 4 / block_size, 0)) #   bbat_len = initial_bbat_len + num_mbat_blocks #   mbat_len = ceil(bbat_len * 4 / block_size) # # the actual bbat allocation table is itself stored throughout the file, and that chain # is stored in the initial blocks, and the mbat blocks. num_mbat_blocks = 0 io = RangesIOResizeable . new @bbat , 'w' , :first_block => AllocationTable :: EOC # truncate now, so that we can simplify size calcs - the mbat blocks will be appended in a # contiguous chunk at the end. # hmmm, i think this truncate should be matched with a truncate of the underlying io. if you # delete a lot of stuff, and free up trailing blocks, the file size never shrinks. this can # be fixed easily, add an io truncate @bbat . truncate! @io . truncate @bbat . block_size * ( @bbat . length + 1 ) while true # get total bbat size. equivalent to @bbat.to_s.length, but for the factoring in of # the mbat blocks. we can't just add the mbat blocks directly to the bbat, as as this iteration # progresses, more blocks may be needed for the bat itself (if there are no more gaps), and the # mbat must remain contiguous. bbat_data_len = ( ( @bbat . length + num_mbat_blocks ) * 4 / @bbat . block_size . to_f ) . ceil * @bbat . block_size # now storing the excess mbat blocks also increases the size of the bbat: new_num_mbat_blocks = ( [ bbat_data_len / @bbat . block_size - 109 , 0 ] . max * 4 / ( @bbat . block_size . to_f - 4 ) ) . ceil if new_num_mbat_blocks != num_mbat_blocks # need more space for the mbat. num_mbat_blocks = new_num_mbat_blocks elsif io . size != bbat_data_len # need more space for the bat # this may grow the bbat, depending on existing available blocks io . truncate bbat_data_len else break end end # now extract the info we want: ranges = io . ranges bbat_chain = @bbat . chain io . first_block io . close bbat_chain . each { | b | @bbat [ b ] = AllocationTable :: BAT } # tack on the mbat stuff @header . num_bat = bbat_chain . length mbat_blocks = ( 0 ... num_mbat_blocks ) . map do block = @bbat . free_block @bbat [ block ] = AllocationTable :: META_BAT block end @header . mbat_start = mbat_blocks . first || AllocationTable :: EOC # now finally write the bbat, using a not resizable io. # the mode here will be 'r', which allows write atm.  RangesIO . open ( @io , :ranges => ranges ) { | f | f . write @bbat . to_s } # this is the mbat. pad it out. bbat_chain += [ AllocationTable :: AVAIL ] * [ 109 - bbat_chain . length , 0 ] . max @header . num_mbat = num_mbat_blocks if num_mbat_blocks != 0 # write out the mbat blocks now. first of all, where are they going to be? mbat_data = bbat_chain [ 109 .. - 1 ] # expand the mbat_data to include the linked list forward pointers. mbat_data = mbat_data . to_enum ( :each_slice , @bbat . block_size / 4 - 1 ) . to_a . zip ( mbat_blocks [ 1 .. - 1 ] + [ nil ] ) . map { | a , b | b ? a + [ b ] : a } # pad out the last one. mbat_data . last . push ( ( [ AllocationTable :: AVAIL ] * ( @bbat . block_size / 4 - mbat_data . last . length ) ) ) RangesIO . open @io , :ranges => @bbat . ranges ( mbat_blocks ) do | f | f . write mbat_data . flatten . pack ( 'V*' ) end end # now seek back and write the header out @io . seek 0 @io . write @header . to_s + bbat_chain [ 0 , 109 ] . pack ( 'V*' ) @io . flush end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "could be useful with mis - behaving ole documents . or to just clean them up . [CODESPLIT] def repack temp = :file case temp when :file Tempfile . open 'ole-repack' do | io | io . binmode repack_using_io io end when :mem ; StringIO . open ( '' . dup , method ( :repack_using_io ) ) else raise ArgumentError , \"unknown temp backing #{temp.inspect}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "https : // www . snip2code . com / Snippet / 71914 / Parse - link - headers - from - Github - API - in - Ru [CODESPLIT] def parse_link_header ( header , params = { } ) links = Hash . new return links unless header parts = header . split ( ',' ) parts . each do | part , index | section = part . split ( ';' ) url = section [ 0 ] [ / / , 1 ] name = section [ 1 ] [ / / , 1 ] . to_sym links [ name ] = url end return links end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "try to load an embedded object ; call out to the API if not [CODESPLIT] def load_relation ( relationship , position = nil ) if objects = @resource . dig ( \"_embedded\" , relationship ) location = position ? objects [ position ] : objects begin WpApiClient :: Collection . new ( location ) rescue WpApiClient :: ErrorResponse load_from_links ( relationship , position ) end else load_from_links ( relationship , position ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "requests come in as url / params pairs [CODESPLIT] def get_concurrently ( requests ) responses = [ ] @conn . in_parallel do requests . map do | r | responses << get ( r [ 0 ] , r [ 1 ] ) end end responses end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Take the API response and figure out what it is [CODESPLIT] def native_representation_of ( response_body ) # Do we have a collection of objects? if response_body . is_a? Array WpApiClient :: Collection . new ( response_body , @headers ) else WpApiClient :: Entities :: Base . build ( response_body ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "call contract functions by rpc call method [CODESPLIT] def call_func ( method : , params : [ ] , tx : { } ) # rubocop:disable Naming/UncommunicativeMethodParamName data , output_types = function_data_with_ot ( method , params ) resp = @rpc . call_rpc ( :call , params : [ tx . merge ( data : data , to : address ) , \"latest\" ] ) result = resp [ \"result\" ] data = [ Utils . remove_hex_prefix ( result ) ] . pack ( \"H*\" ) return if data . nil? re = decode_abi output_types , data re . length == 1 ? re . first : re end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "call contract functions by sendRawTransaction [CODESPLIT] def send_func ( tx : , private_key : , method : , params : [ ] ) # rubocop:disable Naming/UncommunicativeMethodParamName data , _output_types = function_data_with_ot ( method , params ) transaction = if tx . is_a? ( Hash ) Transaction . from_hash ( tx ) else tx end transaction . data = data resp = @rpc . send_transaction ( transaction , private_key ) resp &. dig ( \"result\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse url to host port and scheme [CODESPLIT] def parse_url uri = URI . parse ( @url ) @host = uri . host @port = uri . port @scheme = uri . scheme end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "wrapper Web3 :: Eth abi encoder for encoded data [CODESPLIT] def function_data_with_ot ( method_name , * params ) web3 = Web3 :: Eth :: Rpc . new host : @host , port : @port , connect_options : { use_ssl : https? } contract = web3 . eth . contract ( abi ) . at ( address ) contract . function_data ( method_name , params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "wrapper for call rpc method [CODESPLIT] def call_rpc ( method , jsonrpc : DEFAULT_JSONRPC , params : DEFAULT_PARAMS , id : DEFAULT_ID ) conn . post ( \"/\" , rpc_params ( method , jsonrpc : jsonrpc , params : params , id : id ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "wrapper for rpc params [CODESPLIT] def rpc_params ( method , jsonrpc : DEFAULT_JSONRPC , params : DEFAULT_PARAMS , id : DEFAULT_ID ) { jsonrpc : jsonrpc , id : id , method : method , params : params } . to_json end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "wrapper faraday object with CITA URL and Content - Type [CODESPLIT] def conn Faraday . new ( url : url ) do | faraday | faraday . headers [ \"Content-Type\" ] = \"application/json\" faraday . request :url_encoded # form-encode POST params faraday . adapter Faraday . default_adapter # make requests with Net::HTTP end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "easy to transfer tokens [CODESPLIT] def transfer ( to : , private_key : , value : , quota : 30_000 ) valid_until_block = block_number [ \"result\" ] . hex + 88 meta_data = get_meta_data ( \"latest\" ) [ \"result\" ] version = meta_data [ \"version\" ] chain_id = if version . zero? meta_data [ \"chainId\" ] elsif version == 1 meta_data [ \"chainIdV1\" ] end transaction = Transaction . new ( nonce : Utils . nonce , valid_until_block : valid_until_block , chain_id : chain_id , to : to , value : value , quota : quota , version : version ) send_transaction ( transaction , private_key ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replace the current storage with the given one . [CODESPLIT] def replace ( new ) if String === new @data . replace ( JSON . parse ( new ) ) else @data . replace ( new ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Call the block between a [ #reload ] and [ #save ] . [CODESPLIT] def commit ( & block ) autosave = @autosave @autosave = false result = nil reload begin result = block . call save rescue reload raise ensure @autosave = autosave end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert the storage to JSON . [CODESPLIT] def to_json io = StringIO . new ( \"{\" ) io << JSON . create_id . to_json << \":\" << self . class . name . to_json << \",\" @data . each { | key , value | io << key . to_json . to_s << \":\" << value . to_json << \",\" } io . seek ( - 1 , IO :: SEEK_CUR ) io << \"}\" io . string end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Time the given block with the given label . [CODESPLIT] def time ( label , & block ) raise ArgumentError , \"no block given\" unless block ` ` begin if block . arity == 0 instance_exec ( block ) else block . call ( self ) end ensure ` ` end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Group the given block . [CODESPLIT] def group ( * args , & block ) raise ArgumentError , \"no block given\" unless block ` ` begin if block . arity == 0 instance_exec ( block ) else block . call ( self ) end ensure ` ` end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Group the given block but collapse it . [CODESPLIT] def group! ( * args , & block ) return unless block_given? ` ` begin if block . arity == 0 instance_exec ( block ) else block . call ( self ) end ensure ` ` end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new { Cookies } wrapper . [CODESPLIT] def [] ( name ) matches = ` ` . scan ( / #{ Regexp . escape ( name . encode_uri_component ) } / ) return if matches . empty? result = matches . flatten . map { | value | JSON . parse ( value . decode_uri_component ) } result . length == 1 ? result . first : result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set a cookie . [CODESPLIT] def []= ( name , value , options = { } ) string = value . is_a? ( String ) ? value : JSON . dump ( value ) encoded_value = encode ( name , string , @options . merge ( options ) ) ` #{ encoded_value } ` end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / MethodLength rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / PerceivedComplexity [CODESPLIT] def scan raise IOError , \"There's a invalid or missing file\" if @file . nil? unmarked_group_found = false multiple_marked_found = false result = Hash . new { | hash , key | hash [ key ] = [ ] } result . tap do | effect | begin Timeout . timeout ( @config . scan_timeout ) do detect_groups unless @groups_detected end rescue Timeout :: Error raise_watcher :timed_out_watcher return effect end @groups . each_pair do | _label , group | marks = Hash . new { | hash , key | hash [ key ] = [ ] } group . marks . each_pair do | line , value | value . each do | mark | marks [ line ] << mark . value if mark . marked? ( config . intensity_percentual ) && mark . value end multiple_marked_found = true if marks [ line ] . size > 1 unmarked_group_found = true if marks [ line ] . empty? end effect [ group . label . to_sym ] = marks end raise_watcher :scan_unmarked_watcher , effect if unmarked_group_found raise_watcher :scan_multiple_marked_watcher , effect if multiple_marked_found if unmarked_group_found || multiple_marked_found raise_watcher :scan_mark_watcher , effect , unmarked_group_found , multiple_marked_found end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / MethodLength rubocop : enable Metrics / CyclomaticComplexity rubocop : enable Metrics / PerceivedComplexity rubocop : disable Metrics / MethodLength rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / PerceivedComplexity rubocop : disable Metrics / BlockNesting [CODESPLIT] def detect_groups if @config . scan_mode == :grid scanner = FloodScan . new ( @file . dup ) @groups . each_pair do | _label , group | group_center = group . expected_coordinates . center x = group_center [ :x ] y = group_center [ :y ] width = group . expected_coordinates . width height = group . expected_coordinates . height block = scanner . scan ( Magick :: Point . new ( x , y ) , width , height ) if ! block . empty? group . coordinates = Coordinates . new ( block ) marks_blocks = find_marks_grid ( group ) marks_blocks . each do | mark | mark_width = ImageUtils . calc_width ( mark [ :x1 ] , mark [ :x2 ] ) mark_height = ImageUtils . calc_height ( mark [ :y1 ] , mark [ :y2 ] ) mark_file = @original_file . crop ( mark [ :x1 ] , mark [ :y1 ] , mark_width , mark_height ) o_mark = Mark . new group : group , coordinates : coordinate ( mark ) , image_str : ImageUtils . export_file_to_str ( mark_file ) , line : mark [ :line ] group . marks [ mark [ :line ] ] << o_mark end else @groups_not_detected << group . label end end else file_str = ImageUtils . export_file_to_str ( @file ) original_file_str = ImageUtils . export_file_to_str ( @original_file ) incorrect_bubble_line_found = Hash . new { | hash , key | hash [ key ] = [ ] } bubbles_adjusted = [ ] incorrect_expected_lines = false @groups . each_pair do | _label , group | next unless group . expected_coordinates . any? line = 0 group_center = group . expected_coordinates . center block = find_block_marks ( file_str , group_center [ :x ] , group_center [ :y ] , group ) next unless block group . coordinates = Coordinates . new ( block ) marks_blocks = find_marks ( original_file_str , group ) marks_blocks . sort! { | a , b | a [ :y1 ] <=> b [ :y1 ] } mark_ant = nil marks_blocks . each do | mark | mark_width = ImageUtils . calc_width ( mark [ :x1 ] , mark [ :x2 ] ) mark_height = ImageUtils . calc_height ( mark [ :y1 ] , mark [ :y2 ] ) next unless mark_width >= group . mark_width_with_down_tolerance && mark_height >= group . mark_height_with_down_tolerance mark_positions = mark [ :y1 ] - 10 .. mark [ :y1 ] + 10 line += 1 unless mark_ant && mark_positions . include? ( mark_ant [ :y1 ] ) mark [ :line ] = line mark_ant = mark end marks_blocks . delete_if { | m | m [ :line ] . nil? } marks_blocks . sort_by! { | a | [ a [ :line ] , a [ :x1 ] ] } mark_ant = nil marks_blocks . each do | mark | if mark_ant && mark_ant [ :line ] == mark [ :line ] mark_ant_center = ImageUtils . image_center ( mark_ant ) mark_center = ImageUtils . image_center ( mark ) if ( mark_ant_center [ :x ] - mark_center [ :x ] ) . abs < 10 mark [ :conflict ] = true mark [ :conflicting_mark ] = mark_ant else mark_ant = mark end else mark_ant = mark end end marks_blocks . delete_if { | m | m [ :conflict ] } first_position = 0 elements_position_count = 0 marks_blocks . map { | m | m [ :line ] } . each do | dash | marks = marks_blocks . select { | m | m [ :line ] == dash } if marks . count == group . marks_options . count first_position += marks . first [ :x1 ] elements_position_count += 1 end end if elements_position_count . positive? first_position /= elements_position_count distance = group . distance_between_marks * ( group . marks_options . count - 1 ) last_position = first_position + distance marks_blocks . delete_if do | mark | mark [ :x1 ] < first_position - 10 || mark [ :x1 ] > last_position + 10 end marks_blocks . map { | m | m [ :line ] } . each do | dash | loop do reprocess = false marks = marks_blocks . select { | m | m [ :line ] == dash } marks . each_with_index do | current_mark , index | if index . zero? first_mark_position = first_position - 5 .. first_position + 5 unless first_mark_position . include? ( current_mark [ :x1 ] ) new_mark = { x1 : first_position , x2 : first_position + group . mark_width , y1 : current_mark [ :y1 ] , y2 : current_mark [ :y1 ] + group . mark_height , line : dash } marks_blocks << new_mark marks_blocks . sort_by! { | a | [ a [ :line ] , a [ :x1 ] ] } bubbles_adjusted << new_mark reprocess = true break end end next_mark = marks [ index + 1 ] distance = 0 distance = next_mark [ :x1 ] - current_mark [ :x1 ] if next_mark next unless distance > group . distance_between_marks + 10 || next_mark . nil? && index + 1 < group . marks_options . count new_x1 = current_mark [ :x1 ] + group . distance_between_marks new_mark = { x1 : new_x1 , x2 : new_x1 + group . mark_width , y1 : current_mark [ :y1 ] , y2 : current_mark [ :y1 ] + group . mark_height , line : dash } marks_blocks << new_mark marks_blocks . sort_by! { | a | [ a [ :line ] , a [ :x1 ] ] } bubbles_adjusted << new_mark reprocess = true break end break unless reprocess end end end marks_blocks . each do | mark | mark_width = ImageUtils . calc_width ( mark [ :x1 ] , mark [ :x2 ] ) mark_height = ImageUtils . calc_height ( mark [ :y1 ] , mark [ :y2 ] ) mark_file = @original_file . crop ( mark [ :x1 ] , mark [ :y1 ] , mark_width , mark_height ) o_mark = Mark . new group : group , coordinates : coordinate ( mark ) , image_str : ImageUtils . export_file_to_str ( mark_file ) , line : mark [ :line ] group . marks [ mark [ :line ] ] << o_mark if mark [ :line ] <= group . expected_lines end incorrect_expected_lines = group . incorrect_expected_lines group . marks . each_pair do | dash , marks | if marks . count != group . marks_options . count incorrect_bubble_line_found [ group . label . to_sym ] << dash end end end @groups_detected = true if incorrect_bubble_line_found . any? || bubbles_adjusted . any? || incorrect_expected_lines raise_watcher :incorrect_group_watcher , incorrect_expected_lines , incorrect_bubble_line_found , bubbles_adjusted . flatten end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / MethodLength rubocop : enable Metrics / CyclomaticComplexity rubocop : enable Metrics / PerceivedComplexity rubocop : enable Metrics / BlockNesting rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / MethodLength rubocop : disable Metrics / PerceivedComplexity rubocop : disable Metrics / BlockNesting [CODESPLIT] def find_block_marks ( image , x , y , group ) expected_coordinates = group . expected_coordinates found_blocks = [ ] expected_width = expected_coordinates . width expected_height = expected_coordinates . height block = nil while x <= expected_coordinates . x2 && y <= expected_coordinates . y2 if image [ y ] && image [ y ] [ x ] == ' ' block = find_in_blocks ( found_blocks , x , y ) unless block block = find_block ( image , x , y ) found_blocks << block block [ :width ] = ImageUtils . calc_width ( block [ :x1 ] , block [ :x2 ] ) block [ :height ] = ImageUtils . calc_height ( block [ :y1 ] , block [ :y2 ] ) if @config . scan_mode == :grid unless block [ :width ] <= ( expected_width + group . block_width_tolerance ) && block [ :width ] >= ( expected_width - group . block_width_tolerance ) if block [ :width ] > expected_width + group . block_width_tolerance ajust_width = block [ :width ] - expected_width if @config . auto_ajust_block_width == :left block [ :x2 ] = ( block [ :x2 ] - ajust_width ) + @config . edge_level block [ :width ] = expected_width + @config . edge_level elsif @config . auto_ajust_block_width == :right block [ :x1 ] = ( block [ :x1 ] + ajust_width ) - @config . edge_level block [ :width ] = expected_width + @config . edge_level end else block [ :width ] = 0 end end unless block [ :height ] <= ( expected_height + group . block_height_tolerance ) && block [ :height ] >= ( expected_height - group . block_height_tolerance ) if block [ :height ] > expected_height + group . block_height_tolerance ajust_width = block [ :height ] - expected_height if @config . auto_ajust_block_height == :top block [ :y2 ] = ( block [ :y2 ] - ajust_height ) + @config . edge_level block [ :height ] = expected_height + @config . edge_level elsif @config . auto_ajust_block_height == :bottom block [ :y1 ] = ( block [ :y1 ] + ajust_height ) - @config . edge_level block [ :height ] = expected_height + @config . edge_level end else block [ :height ] = 0 end end end block_width_with_tolerance = block [ :width ] + group . block_width_tolerance block_height_with_tolerance = block [ :height ] + group . block_height_tolerance return block if block_width_with_tolerance >= expected_width && block_height_with_tolerance >= expected_height end end x += 1 y += 1 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / CyclomaticComplexity rubocop : enable Metrics / MethodLength rubocop : enable Metrics / PerceivedComplexity rubocop : enable Metrics / BlockNesting [CODESPLIT] def find_marks_grid ( group ) block = group . coordinates blocks = [ ] blocks . tap do | chunks | lines = group . expected_lines columns = group . marks_options . size distance_lin = group . mark_height distance_col = group . mark_width lines . times do | lin | columns . times do | col | chunks << { x1 : block . x1 + ( col * distance_col ) , y1 : block . y1 + ( lin * distance_lin ) , x2 : block . x1 + ( col * distance_col ) + distance_col , y2 : block . y1 + ( lin * distance_lin ) + distance_lin , line : lin + 1 } end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / MethodLength rubocop : disable Metrics / PerceivedComplexity rubocop : disable Metrics / BlockNesting [CODESPLIT] def find_marks ( image , group ) block = group . coordinates y = block . y1 blocks = [ ] blocks . tap do | chunks | while y < block . y2 x = block . x1 while x < block . x2 if image [ y ] [ x ] == ' ' x += 1 next end result = find_in_blocks ( chunks , x , y ) unless result result = find_block ( image , x , y , '.' , block ) mark_width = ImageUtils . calc_width ( result . values_at ( :x1 , :x2 ) ) mark_height = ImageUtils . calc_height ( result . values_at ( :y1 , :y2 ) ) if mark_width > group . mark_width_with_up_tolerance distance_x1 = x - result [ :x1 ] distance_x2 = result [ :x2 ] - x if distance_x1 <= distance_x2 result [ :x2 ] = result [ :x1 ] + group . mark_width else result [ :x1 ] = result [ :x2 ] - group . mark_width end end if mark_height > group . mark_height_with_up_tolerance distance_y1 = y - result [ :y1 ] distance_y2 = result [ :y2 ] - y if distance_y1 <= distance_y2 result [ :y2 ] = result [ :y1 ] + group . mark_height else result [ :y1 ] = result [ :y2 ] - group . mark_height end end chunks << result unless chunks . any? { | b | b == result } end x += 1 end y += 1 end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / CyclomaticComplexity rubocop : enable Metrics / MethodLength rubocop : enable Metrics / PerceivedComplexity rubocop : enable Metrics / BlockNesting [CODESPLIT] def flag_position ( position ) raise IOError , \"There's a invalid or missing file\" if @file . nil? files = @original_file . dup files . tap do | file | add_mark ( file , position ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / MethodLength [CODESPLIT] def flag_all_marks raise IOError , \"There's a invalid or missing file\" if @file . nil? @original_file . dup . tap do | file | begin Timeout . timeout ( @config . scan_timeout ) do detect_groups unless @groups_detected end rescue Timeout :: Error raise_watcher :timed_out_watcher return file end @groups . each_pair do | _label , group | dr = Magick :: Draw . new dr . stroke_width = 5 dr . stroke ( COLORS [ 3 ] ) dr . line ( group . expected_coordinates . values_at ( :x1 , :y1 , :x2 , :y1 ) ) dr . line ( group . expected_coordinates . values_at ( :x2 , :y1 , :x2 , :y2 ) ) dr . line ( group . expected_coordinates . values_at ( :x2 , :y2 , :x1 , :y2 ) ) dr . line ( group . expected_coordinates . values_at ( :x1 , :y2 , :x1 , :y1 ) ) dr . draw ( file ) next unless group . coordinates dr = Magick :: Draw . new dr . stroke_width = 5 dr . stroke ( COLORS [ 5 ] ) dr . line ( group . coordinates . values_at ( :x1 , :y1 , :x2 , :y1 ) ) dr . line ( group . coordinates . values_at ( :x2 , :y1 , :x2 , :y2 ) ) dr . line ( group . coordinates . values_at ( :x2 , :y2 , :x1 , :y2 ) ) dr . line ( group . coordinates . values_at ( :x1 , :y2 , :x1 , :y1 ) ) dr . draw ( file ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / MethodLength [CODESPLIT] def add_mark ( file , position , mark = nil ) dr = Magick :: Draw . new if @config . scan_mode == :grid x = position [ :x ] - 9 y = position [ :y ] + 5 intensity = mark . intensity ? mark . intensity . ceil . to_s : '+' dr . annotate ( file , 0 , 0 , x , y , intensity ) do self . pointsize = 15 self . fill = COLORS [ 2 ] end dr = Magick :: Draw . new dr . stroke_width = 2 dr . stroke ( COLORS [ 1 ] ) dr . line ( mark . coordinates . values_at ( :x1 , :y1 , :x2 , :y1 ) ) dr . line ( mark . coordinates . values_at ( :x2 , :y1 , :x2 , :y2 ) ) dr . line ( mark . coordinates . values_at ( :x2 , :y2 , :x1 , :y2 ) ) dr . line ( mark . coordinates . values_at ( :x1 , :y2 , :x1 , :y1 ) ) else dr . annotate ( file , 0 , 0 , position [ :x ] - 9 , position [ :y ] + 11 , '+' ) do self . pointsize = 30 self . fill = '#900000' end dr = Magick :: Draw . new dr . fill = '#FF0000' dr . point ( position [ :x ] , position [ :y ] ) dr . point ( position [ :x ] , position [ :y ] + 1 ) dr . point ( position [ :x ] + 1 , position [ :y ] ) dr . point ( position [ :x ] + 1 , position [ :y ] + 1 ) end dr . draw ( file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : The Savon client to send SOAP requests with . [CODESPLIT] def client @client ||= Savon . client ( wsdl ) do | wsdl | wsdl . endpoint = endpoint end . tap do | client | client . config . soap_header = soap_headers client . http . auth . ssl . verify_mode = :none end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Performs a SOAP request . If the session is invalid it will attempt to reauthenticate by called the reauthentication handler if present . [CODESPLIT] def request ( * args , & block ) authenticate! unless session_id retries = authentication_retries begin perform_request ( args , block ) rescue Savon :: SOAP :: Fault => e if e . message =~ / / && authentication_handler && retries > 0 authenticate! retries -= 1 retry end raise end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal Calls the authentication handler which should set [CODESPLIT] def authenticate! options = authentication_handler . call ( self , @options ) @options . merge! ( options ) client . config . soap_header = soap_headers end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Unzips the returned zip file to the location . [CODESPLIT] def extract_to ( destination ) return on_complete { | job | job . extract_to ( destination ) } unless started? with_tmp_zip_file do | file | unzip ( file , destination ) end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Unzips source to destination . [CODESPLIT] def unzip ( source , destination ) Zip :: File . open ( source ) do | zip | zip . each do | f | path = File . join ( destination , f . name ) FileUtils . mkdir_p ( File . dirname ( path ) ) zip . extract ( f , path ) { true } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Writes the zip file content to a temporary location so it can be extracted . [CODESPLIT] def with_tmp_zip_file file = Tempfile . new ( 'retrieve' ) begin file . binmode file . write ( zip_file ) file . rewind yield file ensure file . close file . unlink end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Starts a heart beat in a thread which polls the job status until it has completed or timed out . [CODESPLIT] def start_heart_beat if threading? Thread . abort_on_exception = true @heart_beat ||= Thread . new run_loop else run_loop . call end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Starts the run loop and blocks until the job has completed or failed . [CODESPLIT] def run_loop proc { delay = DELAY_START loop do @status = nil sleep ( delay = delay * DELAY_MULTIPLIER ) trigger :on_poll if completed? || error? trigger callback_type Thread . stop if threading? break end end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Perform the login request . [CODESPLIT] def login response = client . request ( :login ) do soap . body = { :username => username , :password => password } end response . body [ :login_response ] [ :result ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Savon client . [CODESPLIT] def client @client ||= Savon . client ( Metaforce . configuration . partner_wsdl ) do | wsdl | wsdl . endpoint = Metaforce . configuration . endpoint end . tap { | client | client . http . auth . ssl . verify_mode = :none } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Initializes a new instance of a manifest ( package . xml ) file . [CODESPLIT] def to_xml xml_builder = Nokogiri :: XML :: Builder . new do | xml | xml . Package ( 'xmlns' => 'http://soap.sforce.com/2006/04/metadata' ) { self . each do | key , members | xml . types { members . each do | member | xml . members member end xml . name key . to_s . camelize } end xml . version Metaforce . configuration . api_version } end xml_builder . to_xml end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Parses a package . xml file [CODESPLIT] def parse ( file ) document = Nokogiri :: XML ( file ) . remove_namespaces! document . xpath ( '//types' ) . each do | type | name = type . xpath ( 'name' ) . first . content key = name . underscore . to_sym type . xpath ( 'members' ) . each do | member | self [ key ] << member . content end end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Creates a zip file with the contents of the directory . [CODESPLIT] def zip_file path = Dir . mktmpdir File . join ( path , 'deploy.zip' ) . tap do | path | Zip :: File . open ( path , Zip :: File :: CREATE ) do | zip | Dir [ \"#{@path}/**/**\" ] . each do | file | zip . add ( file . sub ( \"#{File.dirname(@path)}/\" , '' ) , file ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new object with given UUID . [CODESPLIT] def new_with_uuid ( klass , uuid ) if klass . is_a? ( String ) klass = Object . const_get ( klass ) end object = klass . new ( self , uuid ) object . initialize_defaults object end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new group with given UUID . [CODESPLIT] def new_group_with_uuid ( name , uuid , path = nil , source_tree = :group ) main_group . new_group_with_uuid ( name , uuid , path , source_tree ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new group with given UUID . [CODESPLIT] def new_group_with_uuid ( name , uuid , path = nil , source_tree = :group ) group = project . new_with_uuid ( PBXGroup , uuid ) children << group group . name = name group . set_source_tree ( source_tree ) group . set_path ( path ) group end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a file reference with given UUID . [CODESPLIT] def new_reference_with_uuid ( path , uuid , source_tree = :group ) # customize `FileReferencesFactory.new_file_reference` path = Pathname . new ( path ) ref = self . project . new_with_uuid ( PBXFileReference , uuid ) self . children << ref GroupableHelper . set_path_with_source_tree ( ref , path , source_tree ) ref . set_last_known_file_type # customize `FileReferencesFactory.configure_defaults_for_file_reference` if ref . path . include? ( '/' ) ref . name = ref . path . split ( '/' ) . last end if File . extname ( ref . path ) . downcase == '.framework' ref . include_in_index = nil end ref end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds the file reference with given UUID . [CODESPLIT] def add_file_reference_with_uuid ( file_ref , uuid , avoid_duplicates = false ) if avoid_duplicates && existing = build_file ( file_ref ) existing else build_file = project . new_with_uuid ( PBXBuildFile , uuid ) build_file . file_ref = file_ref files . insert ( 0 , build_file ) build_file end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] root_path The path provided will be used for detecting Xcode project and Seedfile . [CODESPLIT] def install self . prepare_requirements self . analyze_dependencies self . execute_seedfile self . remove_seeds self . install_seeds self . configure_project self . configure_phase self . project . save self . build_lockfile @seeds = { } @locks = { } @targets = { } @source_files = { } @file_references = [ ] @swift_seedname_prefix = false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read Xcode project Seedfile and lockfile . An exception will be raised if there is no . xcodeproj file or Seedfile in the { #root_path } . [CODESPLIT] def prepare_requirements # .xcodeproj project_filename = Dir . glob ( \"#{root_path}/*.xcodeproj\" ) [ 0 ] if project_filename self . project = Xcodeproj :: Project . open ( project_filename ) end # Seedfile begin self . seedfile = File . read ( self . seedfile_path ) rescue Errno :: ENOENT raise Seeds :: Exception . new \"Couldn't find Seedfile.\" end # Seedfile.lock - optional begin self . lockfile = File . read ( self . lockfile_path ) rescue Errno :: ENOENT end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parses Seedfile . lockfile into { #lockfile } . [CODESPLIT] def analyze_dependencies say \"Anaylizing dependencies\" # Seedfile.lock if self . lockfile locks = YAML . load ( self . lockfile ) locks [ \"SEEDS\" ] . each do | lock | seed = Seeds :: Seed . new seed . name = lock . split ( ' (' ) [ 0 ] seed . version = lock . split ( '(' ) [ 1 ] . split ( ')' ) [ 0 ] if seed . version . start_with? '$' seed . commit = seed . version [ 1 .. - 1 ] seed . version = nil end self . locks [ seed . name ] = seed end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes { #seedfile } using eval [CODESPLIT] def execute_seedfile @current_target_name = nil # Sets `@swift_seedname_prefix` as `true`. # # @!scope method # @!visibility private # def swift_seedname_prefix! ( ) @swift_seedname_prefix = true end # Set current Xcode project with given path. # # @!scope method # @!visibility private # def xcodeproj ( path ) proejct_filename = File . join ( self . root_path , path ) self . project = Xcodeproj :: Project . open ( proejct_filename ) self . validate_project end # Sets `@current_target_name` and executes code block. # # @param [String] names The name of target. # # @!scope method # @!visibility private # def target ( * names , & code ) self . validate_project names . each do | name | name = name . to_s # use string instead of symbol target = self . project . target_named ( name ) if not target raise Seeds :: Exception . new \"#{self.project.path.basename} doesn't have a target `#{name}`\" end @current_target_name = name code . call ( ) end @current_target_name = nil end def local ( name , source_dir , options = { } ) self . validate_project if not @current_target_name target self . project . targets . map ( :name ) do send ( __callee__ , name , source_dir , options ) end else seed = Seeds :: Seed :: LocalSeed . new if not name raise Seeds :: Exception . new \"Need a name to identifier.\" else seed . name = name end if not source_dir raise Seeds :: Exception . new \"Need a source dir.\" else seed . source_dir = source_dir end seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' if seed . files . kind_of? String seed . files = [ seed . files ] end seed . exclude_files = options [ :exclude_files ] || [ ] self . seeds [ seed . name ] = seed self . targets [ seed . name ] ||= [ ] self . targets [ seed . name ] << @current_target_name . to_s end end # Creates a new instance of {#Seeds::Seed::GitHub} and adds to {#seeds}. # # @see #Seeds::Seed::GitHub # # @!scope method # @!visibility private # def github ( repo , tag , options = { } ) self . validate_project if not @current_target_name # apply to all targets target self . project . targets . map ( :name ) do send ( __callee__ , repo , tag , options ) end elsif repo . split ( '/' ) . count != 2 raise Seeds :: Exception . new \"#{repo}: GitHub should have both username and repo name.\\n\" \"    (e.g. `devxoul/JLToast`)\" else seed = Seeds :: Seed :: GitHub . new seed . url = \"https://github.com/#{repo}\" seed . name = repo . split ( '/' ) [ 1 ] if tag . is_a? ( String ) if options [ :commit ] raise Seeds :: Exception . new \"#{repo}: Version and commit are both specified.\" end seed . version = tag seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] elsif tag . is_a? ( Hash ) options . merge! ( tag ) seed . commit = options [ :commit ] [ 0 .. 6 ] seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] end if seed . files . kind_of? ( String ) seed . files = [ seed . files ] end if seed . exclude_files . kind_of? ( String ) seed . exclude_files = [ seed . exclude_files ] end self . seeds [ seed . name ] = seed self . targets [ seed . name ] ||= [ ] self . targets [ seed . name ] << @current_target_name . to_s end end # Creates a new instance of {#Seeds::Seed::BitBucket} and adds to # {#seeds}. # # @see #Seeds::Seed::BitBucket # # @!scope method # @!visibility private # def bitbucket ( repo , tag , options = { } ) self . validate_project if not @current_target_name # apply to all targets target self . project . targets . map ( :name ) do send ( __callee__ , repo , tag , options ) end elsif repo . split ( '/' ) . count != 2 raise Seeds :: Exception . new \"#{repo}: BitBucket should have both username and repo name.\\n\" \"    (e.g. `devxoul/JLToast`)\" else seed = Seeds :: Seed :: BitBucket . new seed . url = \"https://bitbucket.org/#{repo}\" seed . name = repo . split ( '/' ) [ 1 ] if tag . is_a? ( String ) if options [ :commit ] raise Seeds :: Exception . new \"#{repo}: Version and commit are both specified.\" end seed . version = tag seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] elsif tag . is_a? ( Hash ) options . merge! ( tag ) seed . commit = options [ :commit ] [ 0 .. 6 ] seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] end if seed . files . kind_of? ( String ) seed . files = [ seed . files ] end if seed . exclude_files . kind_of? ( String ) seed . exclude_files = [ seed . exclude_files ] end self . seeds [ seed . name ] = seed self . targets [ seed . name ] ||= [ ] self . targets [ seed . name ] << @current_target_name . to_s end end def git ( repo , tag , options = { } ) self . validate_project if not @current_target_name target self . project . targets . map ( :name ) do send ( __callee__ , repo , tag , options ) end elsif not repo . end_with? \".git\" raise Seeds :: Exception . new \"#{repo}: is not a valid git repo.\\n\" else seed = Seeds :: Seed :: CustomSeed . new seed . url = repo seed . name = repo . split ( '/' ) . last . sub / / , '' if tag . is_a? String if options [ :commit ] raise Seeds :: Exception . new \"#{repo}: Version and commit are both specified.\" end seed . version = tag seed . files = options [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] elsif tag . is_a? Hash seed . commit = tag [ :commit ] [ 0 .. 6 ] seed . files = tag [ :files ] || '**/*.{h,m,mm,swift}' seed . exclude_files = options [ :exclude_files ] || [ ] end if seed . files . kind_of? String seed . files = [ seed . files ] end if seed . exclude_files . kind_of? String seed . exclude_files = [ seed . exclude_files ] end self . seeds [ seed . name ] = seed self . targets [ seed . name ] ||= [ ] self . targets [ seed . name ] << @current_target_name . to_s end end eval seedfile end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes disused seeds . [CODESPLIT] def remove_seeds removings = self . locks . keys - self . seeds . keys removings . each do | name | say \"Removing #{name} (#{self.locks[name].version})\" . red dirname = File . join ( self . root_path , \"Seeds\" , name ) FileUtils . rm_rf ( dirname ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Installs new seeds or updates existing seeds . [CODESPLIT] def install_seeds seed_dir = File . join self . root_path , \"Seeds\" if not Dir . exist? seed_dir Dir . mkdir seed_dir end self . seeds . sort . each do | name , seed | dirname = File . join ( self . root_path , \"Seeds\" , seed . name ) if seed . instance_of? Seeds :: Seed :: LocalSeed self . install_local_seed ( seed , dirname ) else self . install_seed ( seed , dirname ) end next if not seed . files # add seed files to `source_files` self . source_files [ name ] = [ ] seed . files . each do | file | paths = Dir . glob ( File . join ( dirname , file ) ) # exclude files seed . exclude_files . each do | exclude_file | exclude_paths = Dir . glob ( File . join ( dirname , exclude_file ) ) exclude_paths . each do | exclude_path | paths . delete ( exclude_path ) end end paths . each do | path | path = self . path_with_prefix ( seed . name , path ) self . source_files [ name ] . push ( path ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Installs new seed or updates existing seed in { #dirname } . [CODESPLIT] def install_seed ( seed , dirname ) # if remote url has changed, remove directory and clone again remote_url = ` #{ Shellwords . escape ( dirname ) } ` . strip if remote_url != seed . url FileUtils . rm_rf ( dirname ) end # clone and return if not exists if not File . exist? ( dirname ) say \"Installing #{seed.name} (#{seed.version or seed.commit})\" . green command = \"git clone #{seed.url}\" command += \" -b #{seed.version}\" if seed . version command += \" #{Shellwords.escape(dirname)} 2>&1\" output = ` #{ command } ` unable_to_access = output . include? ( \"unable to access\" ) if unable_to_access and output . include? ( \"Failed to connect to\" ) raise Seeds :: Exception . new \"#{seed.name}: Failed to connect to #{seed.url}. \\n#{output}\" end not_found = output . include? ( \"not found\" ) if not_found and output . include? ( \"repository\" ) raise Seeds :: Exception . new \"#{seed.name}: Couldn't find the repository.\" elsif not_found and output . include? ( \"upstream\" ) raise Seeds :: Exception . new \"#{seed.name}: Couldn't find the tag `#{seed.version}`.\" end if seed . commit and not seed . version # checkout to commit output = ` #{ Shellwords . escape ( dirname ) } \\\n #{ seed . commit } ` if output . include? ( \"did not match any\" ) raise Seeds :: Exception . new \"#{seed.name}: Couldn't find the commit `#{seed.commit}`.\" end end return end # discard local changes ` #{ Shellwords . escape ( dirname ) } \\\n \\\n \\\n ` if lock = self . locks [ seed . name ] lock_version = lock . version lock_commit = lock . commit end if seed . version == lock_version and seed . commit == lock_commit say \"Using #{seed.name} (#{lock_version or lock_commit})\" return end if seed . version say \"Installing #{seed.name} #{seed.version}\" \" (was #{lock_version or lock_commit})\" . green output = ` #{ Shellwords . escape ( dirname ) } \\\n #{ seed . version } \\\n #{ seed . version } ` if output . include? ( \"Couldn't find\" ) raise Seeds :: Exception . new \"#{seed.name}: Couldn't find the tag or branch `#{seed.version}`.\" end elsif seed . commit say \"Installing #{seed.name} #{seed.commit}\" \" (was #{lock_version or lock_commit})\" . green output = ` #{ Shellwords . escape ( dirname ) } #{ seed . commit } ` if output . include? ( \"did not match any\" ) raise Seeds :: Exception . new \"#{seed.name}: Couldn't find the commit `#{seed.commit}`.\" . red end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Append seed name as a prefix to file name and returns the path . [CODESPLIT] def path_with_prefix ( seedname , path ) if @swift_seedname_prefix components = path . split ( \"/\" ) prefix = seedname + \"_\" # Alamofire_ filename = components [ - 1 ] # Alamofire.swift extension = File . extname ( filename ) # .swift # only swift files can have prefix in filename if extension == '.swift' and not filename . start_with? prefix filename = prefix + filename # Alamofire_Alamofire.swift newpath = components [ 0 ... - 1 ] . join ( '/' ) + '/' + filename File . rename ( path , newpath ) # rename real files path = newpath end end path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds source files to the group Seeds and save its reference to { #file_references } and removes disused sources files [CODESPLIT] def configure_project say \"Configuring #{self.project.path.basename}\" group = self . project [ \"Seeds\" ] if group group . clear else uuid = Xcodeproj :: uuid_with_name \"Seeds\" group = self . project . new_group_with_uuid ( \"Seeds\" , uuid ) end # remove existing group that doesn't have any file references group . groups . each do | seedgroup | valid_files = seedgroup . children . select do | child | File . exist? ( child . real_path ) end if valid_files . length == 0 seedgroup . remove_from_project end end self . source_files . each do | seedname , filepaths | uuid = Xcodeproj :: uuid_with_name \"Seeds/#{seedname}\" seedgroup = group [ seedname ] || group . new_group_with_uuid ( seedname , uuid ) filepaths . each do | path | filename = path . split ( '/' ) [ - 1 ] relpath = path [ self . root_path . length .. - 1 ] uuid = Xcodeproj :: uuid_with_name relpath file_reference = seedgroup [ filename ] || seedgroup . new_reference_with_uuid ( path , uuid ) self . file_references << file_reference end unusing_files = seedgroup . files - self . file_references unusing_files . each { | file | file . remove_from_project } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds file references to the Sources Build Phase . [CODESPLIT] def configure_phase self . project . targets . each do | target | begin phase = target . sources_build_phase # support resources phase resource_phase = target . resources_build_phase next unless phase rescue NoMethodError next end # remove zombie build files phase . files_references . each do | file | begin file . real_path rescue phase . files . each do | build_file | phase . files . delete ( build_file ) if build_file . file_ref == file end end end resource_phase . files_references . each do | file | begin file . real_path rescue resource_phase . files . each do | build_file | resource_phase . files . delete ( build_file ) if build_file . file_ref == file end end end removings = [ ] # name of seeds going to be removed from the target addings = [ ] # name of seeds going to be added to the target self . targets . keys . sort . each do | seed_name | target_names = self . targets [ seed_name ] if not target_names . include? ( target . name ) removings << seed_name if not removings . include? ( seed_name ) else addings << seed_name if not addings . include? ( seed_name ) end end self . file_references . each do | file | removings . each do | seed_names | next if not seed_names . include? ( file . parent . name ) phase . files . each do | build_file | phase . files . delete ( build_file ) if build_file . file_ref == file end resource_phase . files . each do | build_file | resource_phase . files . delete ( build_file ) if build_file . file_ref == file end end addings . each do | seed_names | next if file . name . end_with? \".h\" next if not seed_names . include? ( file . parent . name ) uuid = Xcodeproj :: uuid_with_name \"#{target.name}:#{file.name}\" # Treat a file as resource file unless confirm it can be compiled. if self . valid_source_file? ( file ) phase . add_file_reference_with_uuid ( file , uuid , true ) else resource_phase . add_file_reference_with_uuid ( file , uuid , true ) end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determines whether there s a source file . [CODESPLIT] def valid_source_file? filename suffixs = [ \".h\" , \".c\" , \".m\" , \".mm\" , \".swift\" , \".cpp\" ] suffixs . each do | suffix | return true if filename . name . end_with? suffix end return false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Writes Seedfile . lock file . [CODESPLIT] def build_lockfile tree = { \"SEEDS\" => [ ] } self . seeds . each do | name , seed | if not seed . instance_of? Seeds :: Seed :: LocalSeed tree [ \"SEEDS\" ] << \"#{name} (#{seed.version or '$' + seed.commit})\" end end File . write ( self . lockfile_path , YAML . dump ( tree ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create an Aspell speller object [CODESPLIT] def speller return @speller if @speller # raspell is an optional dependency, handle the missing case nicely begin require \"raspell\" rescue LoadError $stderr . puts \"ERROR: Ruby gem \\\"raspell\\\" is not installed.\" exit 1 end # initialize aspell @speller = Aspell . new ( \"en_US\" ) @speller . suggestion_mode = Aspell :: NORMAL # ignore the HTML tags in the text @speller . set_option ( \"mode\" , \"html\" ) @speller end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "evaluate the files to check [CODESPLIT] def files_to_check files = config [ \"check\" ] . reduce ( [ ] ) { | a , e | a + Dir [ e ] } config [ \"ignore\" ] . reduce ( files ) { | a , e | a - Dir [ e ] } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "read a Yaml config file [CODESPLIT] def read_spell_config ( file ) return { } unless File . exist? ( file ) puts \"Loading config file (#{file})...\" if verbose == true require \"yaml\" YAML . load_file ( file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "print the duplicate dictionary entries [CODESPLIT] def report_duplicates ( dict1 , dict2 ) duplicates = dict1 & dict2 return if duplicates . empty? $stderr . puts \"Warning: Found dictionary duplicates in the local dictionary \" \"(#{CUSTOM_SPELL_CONFIG_FILE}):\\n\" duplicates . each { | duplicate | $stderr . puts \"  #{duplicate}\" } $stderr . puts end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return the merged global and the custom spell configs [CODESPLIT] def config return @config if @config @config = read_spell_config ( GLOBAL_SPELL_CONFIG_FILE ) custom_config = read_spell_config ( CUSTOM_SPELL_CONFIG_FILE ) report_duplicates ( config [ \"dictionary\" ] , custom_config [ \"dictionary\" ] . to_a ) custom_config [ \"dictionary\" ] = @config [ \"dictionary\" ] + custom_config [ \"dictionary\" ] . to_a custom_config [ \"dictionary\" ] . uniq! # override the global values by the local if present @config . merge! ( custom_config ) @config end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "check the file using the spellchecker [CODESPLIT] def check_file ( file ) puts \"Checking #{file}...\" if verbose == true # spell check each line separately so we can report error locations properly lines = File . read ( file ) . split ( \"\\n\" ) success = true lines . each_with_index do | text , index | misspelled = misspelled_on_line ( text ) next if misspelled . empty? success = false print_misspelled ( misspelled , index , text ) end success end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute a rake / capistrano task only for given server [CODESPLIT] def invoke_for_server ( server , task , * args ) backup_filter = fetch :filter , { } new_server_filter = Marshal . load ( Marshal . dump ( backup_filter ) ) new_server_filter [ :host ] = server . hostname set :filter , new_server_filter env . setup_filters info I18n . t ( 'dsl.invoke_for_server.set_filter' , task : task , host : server . hostname , scope : :dkdeploy ) invoke! task , args ensure set :filter , backup_filter env . setup_filters end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ OptBase ] opt [CODESPLIT] def opt_help_messages ( opt ) opt . help_messages . empty? ? [ opt . to_s . humanize ] : opt . help_messages end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] value [CODESPLIT] def validate ( value ) results = { } super ( value ) . each do | item | opt = choices [ item . to_sym ] if opt opt_value = opt . value_if_empty . nil? ? true : opt . value_if_empty else opt , opt_value = value_from_pattern ( item ) end results [ opt . to_sym ] = opt . normalize ( opt . validate ( opt_value ) ) end verify_compatibility ( results ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Hash ] values [CODESPLIT] def verify_compatibility ( values ) incompatible . each do | a | last_match = '' a . each do | key | sym = choices [ key ] . to_sym next unless values . key? ( sym ) raise Error , \"Incompatible choices detected: #{last_match}, #{key}\" unless last_match . empty? last_match = key end end values end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] value [CODESPLIT] def validate ( value ) a = super ( value ) . split ( separator ) raise Error , \"Incorrect number of ranges found: #{a.size}, should be 2\" unless a . size == 2 first_integer = a . first . to_i last_integer = a . last . to_i raise Error , 'Argument is not a valid integer range' unless first_integer . to_s == a . first && last_integer . to_s == a . last ( first_integer .. last_integer ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See OptBase#normalize [CODESPLIT] def normalize ( values ) values . each_with_index do | value , index | values [ index ] = super ( value ) end values end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialize attrs : [CODESPLIT] def validate ( value ) path = Pathname . new ( value ) allowed_attrs . each do | key | method = \"check_#{key}\" send ( method , path ) if respond_to? ( method ) && attrs [ key ] end path . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If the path does not exist it will check for the parent directory write permission [CODESPLIT] def check_writable ( path ) raise Error , \"'#{path}' is not writable\" if path . exist? && ! path . writable? || ! path . parent . writable? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Array ] option See OptionParser#on @param [ Hash ] attrs @option attrs [ Boolean ] : required @options attrs [ Array<Symbol > Symbol ] : required_unless @option attrs [ Mixed ] : default The default value to use if the option is not supplied @option attrs [ Mixed ] : value_if_empty The value to use if no argument has been supplied @option attrs [ Array<Symbol > ] : normalize See #normalize [CODESPLIT] def append_help_messages option << \"Default: #{help_message_for_default}\" if default option << \"Value if no argument supplied: #{value_if_empty}\" if value_if_empty option << 'This option is mandatory' if required? option << \"This option is mandatory unless #{required_unless.join(' or ')} is/are supplied\" unless required_unless . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Apply each methods from attrs [ : normalize ] to the value if possible User input should not be used in this attrs [ : normalize ] [CODESPLIT] def normalize ( value ) [ attrs [ :normalize ] ] . each do | method | next unless method . is_a? ( Symbol ) value = value . send ( method ) if value . respond_to? ( method ) end value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Array<OptBase > ] options [CODESPLIT] def add ( * options ) options . each do | option | check_option ( option ) @opts << option @symbols_used << option . to_sym # Set the default option value if it exists # The default value is not validated as it is provided by devs # and should be set to the correct format/value directly @results [ option . to_sym ] = option . default unless option . default . nil? register_callback ( option ) end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensures the opt given is valid [CODESPLIT] def check_option ( opt ) raise Error , \"The option is not an OptBase, #{opt.class} supplied\" unless opt . is_a? ( OptBase ) raise Error , \"The option #{opt.to_sym} is already used !\" if @symbols_used . include? ( opt . to_sym ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ OptBase ] opt [CODESPLIT] def register_callback ( opt ) on ( opt . option ) do | arg | begin if opt . alias? parse! ( opt . alias_for . split ( ' ' ) ) else @results [ opt . to_sym ] = opt . normalize ( opt . validate ( arg ) ) end rescue StandardError => e # Adds the long option name to the message # And raises it as an OptParseValidator::Error if not already one # e.g --proxy Invalid Scheme format. raise e . is_a? ( Error ) ? e . class : Error , \"#{opt.to_long} #{e}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure that all required options are supplied Should be overriden to modify the behavior [CODESPLIT] def post_processing @opts . each do | opt | raise NoRequiredOption , \"The option #{opt} is required\" if opt . required? && ! @results . key? ( opt . to_sym ) next if opt . required_unless . empty? || @results . key? ( opt . to_sym ) fail_msg = \"One of the following options is required: #{opt}, #{opt.required_unless.join(', ')}\" raise NoRequiredOption , fail_msg unless opt . required_unless . any? do | sym | @results . key? ( sym ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] value [CODESPLIT] def validate ( value ) values = super ( value ) . chomp ( ';' ) . split ( '; ' ) headers = { } values . each do | header | raise Error , \"Malformed header: '#{header}'\" unless header . index ( ':' ) val = header . split ( ':' , 2 ) headers [ val [ 0 ] . strip ] = val [ 1 ] . strip end headers end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] value [CODESPLIT] def validate ( value ) uri = Addressable :: URI . parse ( value ) uri = Addressable :: URI . parse ( \"#{default_protocol}://#{value}\" ) if ! uri . scheme && default_protocol unless allowed_protocols . empty? || allowed_protocols . include? ( uri . scheme &. downcase ) # For future refs: will have to check if the uri.scheme exists, # otherwise it means that the value was empty raise Addressable :: URI :: InvalidURIError end uri . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] file_path [CODESPLIT] def << ( file_path ) return self unless File . exist? ( file_path ) ext = File . extname ( file_path ) . delete ( '.' ) raise Error , \"The option file's extension '#{ext}' is not supported\" unless self . class . supported_extensions . include? ( ext ) super ( ConfigFile . const_get ( ext . upcase ) . new ( file_path ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@params [ Hash ] opts @option opts [ Boolean ] : symbolize_keys Whether or not to symbolize keys in the returned hash @option opts [ Array ] : yaml_arguments See https : // ruby - doc . org / stdlib - 2 . 3 . 1 / libdoc / psych / rdoc / Psych . html#method - c - safe_load [CODESPLIT] def parse ( opts = { } ) result = { } each { | option_file | result . deep_merge! ( option_file . parse ( opts ) ) } opts [ :symbolize_keys ] ? result . deep_symbolize_keys : result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ String ] value [CODESPLIT] def validate ( value ) raise Error , \"#{value} is not an integer\" if value . to_i . to_s != value value . to_i end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Conversions Get entities of files in dir [CODESPLIT] def subdir_entities ( dir = @current_dir ) Dir . glob ( dir [ :path ] . gsub ( / \\\\ \\[ \\] / , '\\\\\\\\\\0' ) + '/*' ) . map! { | path | { path : path , time : File . mtime ( path ) , name : File . basename ( path ) } } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fix an entity : time - > DOSTime object name - > abs path in zip & encoded [CODESPLIT] def fix_entity ( entity ) { path : entity [ :path ] , filetime : Zip :: DOSTime . at ( entity [ :time ] || File . mtime ( entity [ :path ] ) ) , binary_name : string_to_bytes ( abs_path_for_entity ( entity ) ) , zip_path : abs_path_for_entity ( entity ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create ASCII - 8bits string . Also convert encoding if needed . [CODESPLIT] def string_to_bytes ( str ) unless @e . nil? || @e == :utf8 if @e == :shift_jis begin str = str . gsub / \\\\ \\uff5e / , '？' str . encode! 'Shift_JIS' , :invalid => :replace , :undef => :replace , :replace => '？' rescue => e end end end [ str ] . pack ( 'a*' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Compression operations Pack file and directory entities and output to stream . [CODESPLIT] def pack ( files ) entities = Entity . entities_from files return if entities . empty? reset_state pack_entities entities while has_dir? cd next_dir pack_current_dir end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pack symlinks if its link path exists in zip [CODESPLIT] def pack_symlinks reset_state @l . each do | link | if @w . path_exists? Entity . linked_path ( link [ :abs_path ] , File . readlink ( link [ :path ] ) ) link [ :name ] = link [ :abs_path ] pack_symbolic_link_entity link end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pack file entities . Directory entities are queued not packed in this method . [CODESPLIT] def pack_entities ( entities ) entities . each do | entity | # ignore bad entities next unless entity . is_a? ( Hash ) && entity [ :path ] path = entity [ :path ] if File . symlink? path postpone_symlink entity elsif File . directory? path postpone_dir entity elsif File . file? path pack_file_entity entity end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write operations [CODESPLIT] def write_file_entry write_entry do | path , filetime , name | write PKHeader . pk0304 ( filetime , name . length , true ) . pack ( 'VvvvvvVVVvv' ) , name ret = deflate_file path write PKHeader . pk0708 ( ret [ :crc ] , ret [ :complen ] , ret [ :uncomplen ] ) . pack ( 'VVVV' ) ret end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / ParameterLists rubocop : enable Metrics / ParameterLists : reek : TooManyStatements [CODESPLIT] def activatable? attributes = { } return false unless search_value . present? attributes = attributes . with_indifferent_access current_search_value = attributes [ search_key ] if current_search_value . is_a? ( Regexp ) || search_value . is_a? ( Regexp ) return false if current_search_value . blank? current_search_value . match? search_value else current_search_value == search_value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / LineLength [CODESPLIT] def activate attributes = { } attributes = attributes . with_indifferent_access attributes [ target_key ] = [ attributes [ target_key ] , target_value ] . compact . join \" \" if activatable? attributes attributes end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / LineLength [CODESPLIT] def add name , content = nil , attributes : { } , activator : menu_activator , & block tag = Navigator :: Tag . new name , content , attributes : attributes , activator : activator return items << tag . render unless block_given? items << tag . prefix items << tag . content instance_eval ( block ) items << tag . suffix end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / ParameterLists rubocop : disable Metrics / LineLength [CODESPLIT] def navigation tag = \"ul\" , attributes : { } , activator : navigation_activator , & block raw Navigator :: Menu . new ( self , tag : tag , attributes : attributes , activator : activator , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render html tag [CODESPLIT] def render content_tag :div , @html_options do concat content_tag ( :div , table_name , class : 'title' ) concat TableSearchField . new ( { store : @store , wrap_form : @options [ :wrap_form ] } ) . render if searchable? concat tag :br , class : 'ui-bibz-clear' end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render if options [ :nav_type ] == \"nav-links\" UiBibz :: Ui :: Core :: Navigations :: NavLinkLink . new ( content , options , html_options ) . render else if options [ :tag_type ] == :span cont = UiBibz :: Ui :: Core :: Navigations :: NavLinkSpan . new ( content , @old_options ) . render else cont = UiBibz :: Ui :: Core :: Navigations :: NavLinkLink . new ( content , options ) . render end #html_options[:class] = remove_class(html_options[:class]) remove_classes UiBibz :: Ui :: Core :: Navigations :: NavLinkList . new ( cont , options , html_options ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render content_tag tag_type , html_options do concat glyph_and_content_html if @content concat header_html if @body concat body_html if @body concat badge_html if @options [ :badge ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add header which is a component [CODESPLIT] def header content = nil , options = nil , html_options = nil , & block @header = UiBibz :: Ui :: Core :: Lists :: Components :: ListHeader . new content , options , html_options , block end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add body which is a component [CODESPLIT] def body content = nil , options = nil , html_options = nil , & block @body = UiBibz :: Ui :: Core :: Lists :: Components :: ListBody . new content , options , html_options , block end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add group list See UiBibz :: Ui :: Core :: List [CODESPLIT] def list content = nil , options = { } , html_options = nil , & block options = options . merge ( { tag_type : @options [ :tag_type ] } ) unless @options [ :tag_type ] . nil? if is_tap ( content , options ) @lists << UiBibz :: Ui :: Core :: Lists :: Components :: List . new ( content , options , html_options ) . tap ( block ) . render else @lists << UiBibz :: Ui :: Core :: Lists :: Components :: List . new ( content , options , html_options , block ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize [CODESPLIT] def pre_render content_tag :div , html_options do concat UiBibz :: Ui :: Core :: Icons :: Glyph . new ( options [ :glyph ] , class : 'mr-2' ) . render unless options [ :glyph ] . nil? concat image_tag ( options [ :img ] , class : 'rounded mr-2' ) unless options [ :img ] . nil? concat content_tag ( :strong , content , class : 'mr-auto' ) concat content_tag ( :small , options [ :time ] , class : 'text-muted' ) unless options [ :time ] . nil? concat close_button end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render content_tag :div , html_options do concat file_field_tag content , class : \"custom-file-input\" , multiple : options [ :multiple ] , disabled : is_disabled? concat label_tag label_name , label_content , class : 'custom-file-label' end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Forms :: Choices :: Button . initialize [CODESPLIT] def choice content = nil , opts = nil , html_options = nil , & block if block . nil? opts = @options . merge ( opts || { } ) else content = @options . merge ( content || { } ) end @items << Choice . new ( content , opts , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Maybe create a class for td_content [CODESPLIT] def td_content record , col content = col . count ? record . send ( col . data_index ) . count : record . send ( col . data_index ) unless content . nil? content = content . strftime ( col . date_format ) unless col . date_format . nil? content = link_to content , action . inject_url ( col . link , record ) unless col . link . nil? content = col . format . call ( @store . records , record ) unless col . format . nil? end content = As . new ( col , record , content , @options ) . render unless col . as . nil? content end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Header which is a component [CODESPLIT] def header content = nil , options = nil , html_options = nil , & block @header = UiBibz :: Ui :: Core :: Notifications :: Components :: ToastHeader . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Add Header which is a component [CODESPLIT] def header content = nil , options = nil , html_options = nil , & block options , content = inherit_options ( content , options , block ) if is_tap ( content , options ) @header = UiBibz :: Ui :: Core :: Boxes :: Components :: CardHeader . new ( content , options , html_options ) . tap ( block ) . render else @header = UiBibz :: Ui :: Core :: Boxes :: Components :: CardHeader . new ( content , options , html_options , block ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Body div which is a component [CODESPLIT] def body content = nil , options = nil , html_options = nil , & block options , content = inherit_options ( content , options , block ) if is_tap ( content , options ) content = ( content || { } ) . merge ( collapse : options . try ( :[] , :collapse ) , parent_collapse : @options [ :parent_collapse ] ) @items << UiBibz :: Ui :: Core :: Boxes :: Components :: CardBody . new ( content , options , html_options ) . tap ( block ) . render else options = ( options || { } ) . merge ( collapse : options . try ( :[] , :collapse ) , parent_collapse : @options [ :parent_collapse ] ) @items << UiBibz :: Ui :: Core :: Boxes :: Components :: CardBody . new ( content , options , html_options , block ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Footer which is a component [CODESPLIT] def footer content = nil , options = nil , html_options = nil , & block options , content = inherit_options ( content , options , block ) @footer = UiBibz :: Ui :: Core :: Boxes :: Components :: CardFooter . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add List group which is a component [CODESPLIT] def list_group content = nil , options = nil , html_options = nil , & block @items << UiBibz :: Ui :: Core :: Boxes :: Components :: CardListGroup . new ( content , options , html_options ) . tap ( block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Image which is a component [CODESPLIT] def image content = nil , options = nil , html_options = nil , & block @items << UiBibz :: Ui :: Core :: Boxes :: Components :: CardImage . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render content_tag :nav , html_options do concat title if brand_position == :left concat navbar_toggle_button_html concat title if brand_position == :right concat body_html end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add navbar nav items See UiBibz :: Ui :: Core :: NavbarNav [CODESPLIT] def nav content = nil , options = nil , html_options = nil , & block options = options || { } @items << UiBibz :: Ui :: Core :: Navigations :: NavbarNav . new ( content , options , html_options ) . tap ( block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add navbar form items See UiBibz :: Ui :: Core :: NavbarForm [CODESPLIT] def form model_or_url , options = { } , & block @items << UiBibz :: Ui :: Core :: Navigations :: NavbarForm . new ( model_or_url , options , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Not use !!!!! Add navbar text items See UiBibz :: Ui :: Core :: NavbarText [CODESPLIT] def text content = nil , options = nil , html_options = nil , & block @items << UiBibz :: Ui :: Core :: Navigations :: NavbarText . new ( content , options , html_options , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Add nav link items See UiBibz :: Ui :: Core :: Navigations :: NavLink [CODESPLIT] def tab content = nil , options = { } , html_options = nil , & block block_given? ? content . merge! ( { nav_type : type , tag_type : @options [ :tag_type ] } ) : options . merge! ( { nav_type : type , tag_type : @options [ :tag_type ] } ) @items << NavLink . new ( content , options , html_options , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add breadcrumb link items See UiBibz :: Ui :: Core :: BreadcrumbLink [CODESPLIT] def link content = nil , options = nil , html_options = nil , & block @links << UiBibz :: Ui :: Core :: Navigations :: Components :: BreadcrumbLink . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render output = [ content_tag ( :p , content , html_options ) ] output << content_tag ( :small , options [ :extra ] ) output . join . html_safe end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "include WillPaginate :: ActionView :: BootstrapLinkRenderer Initialize pagination with component item pagination require WillPaginate gem Render html tag with boostrap pagination theme [CODESPLIT] def render paginate_parameters = { controller : store . controller } paginate_parameters = paginate_parameters . merge ( { store_id : store . id } ) unless store . id . nil? paginate_parameters = paginate_parameters . merge ( store . parameters ) paginate_parameters = paginate_parameters . merge ( { link_type : 'pagination' } ) will_paginate ( store . records , params : paginate_parameters . with_indifferent_access . reject { | k , v | default_parameters? ( k ) || v . blank? } , renderer : WillPaginate :: ActionView :: BootstrapLinkRenderer ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render html tag [CODESPLIT] def render content_tag :div , @html_options do concat UiBibz :: Ui :: Ux :: Tables :: TablePagination . new ( store : @store , wrap_form : @options [ :wrap_form ] ) . render concat UiBibz :: Ui :: Ux :: Tables :: TablePaginationPerPage . new ( store : @store , wrap_form : @options [ :wrap_form ] ) . render concat tag ( :br , class : 'ui-bibz-clear' ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add html component [CODESPLIT] def html content = nil , & block if ! block . nil? context = eval ( \"self\" , block . binding ) @items << context . capture ( block ) else @items << content end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Boxes :: Component . initialize Render html tag [CODESPLIT] def pre_render content_tag :div , html_options do if fluid UiBibz :: Ui :: Core :: Layouts :: Container . new ( content ) . render else content end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try to put it on a line [CODESPLIT] def component_html_options super . merge ( { multiple : options [ :multiple ] , disabled : options [ :state ] == :disabled , include_blank : options [ :include_blank ] , prompt : options [ :prompt ] } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add nav link items See UiBibz :: Ui :: Core :: Navigations :: NavLink [CODESPLIT] def link content = nil , options = { } , html_options = nil , & block block_given? ? content . merge! ( { nav_type : type } ) : options . merge! ( { nav_type : type } ) @items << NavLink . new ( content , options , html_options , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add nav in nav [CODESPLIT] def nav content = nil , options = { } , html_options = nil , & block @items << UiBibz :: Ui :: Core :: Component . new ( Nav . new ( content , options ) . tap ( block ) . render , { } , html_options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add nav dropdown items See UiBibz :: Ui :: Core :: Navigations :: NavDropdown [CODESPLIT] def dropdown content = nil , options = { } , html_options = nil , & block @items << NavDropdown . new ( content , options , html_options ) . tap ( block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add nav link items See UiBibz :: Ui :: Core :: Navigations :: NavLink [CODESPLIT] def link content = nil , options = { } , html_options = nil , & block @items << PaginationLink . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Header which is a component [CODESPLIT] def header content = nil , options = nil , html_options = nil , & block if block . nil? options = @options . merge ( options || { } ) else content = @options . merge ( content || { } ) end @header = UiBibz :: Ui :: Core :: Notifications :: Components :: AlertHeader . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Body which is a component [CODESPLIT] def body content = nil , options = nil , html_options = nil , & block @body = UiBibz :: Ui :: Core :: Notifications :: Components :: AlertBody . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Component . initialize Render html tag [CODESPLIT] def pre_render if options [ :collapse ] content_tag :div , class : join_classes ( \"collapse\" , show ) , id : options [ :collapse ] , \"data-parent\" : \"##{ options[:parent_collapse] }\" do content_tag :div , @items . join . html_safe , html_options end else content_tag :div , @items . join . html_safe , html_options end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Know if component is tapped or not [CODESPLIT] def is_tap content , options ( content [ :tap ] if content . kind_of? ( Hash ) ) || ( options [ :tap ] unless options . nil? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Override this method to add html data [CODESPLIT] def component_html_data # To stimulusjs data_target = html_options . try ( :[] , :data ) . try ( :[] , :target ) || options . try ( :delete , :target ) add_html_data ( :target , data_target ) unless data_target . nil? data_controller = html_options . try ( :[] , :data ) . try ( :[] , :controller ) || options . try ( :delete , :controller ) add_html_data ( :controller , data_controller ) unless data_controller . nil? data_action = html_options . try ( :[] , :data ) . try ( :[] , :action ) || options . try ( :delete , :action ) add_html_data ( :action , data_action ) unless data_action . nil? # To turbolinks data_turbolinks = html_options . try ( :[] , :data ) . try ( :[] , :turbolinks ) || options . try ( :delete , :turbolinks ) add_html_data ( :turbolinks , data_turbolinks ) unless data_turbolinks . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add html data arguments [CODESPLIT] def add_html_data name , value = true html_options [ :data ] = { } if html_options [ :data ] . nil? value = value . kind_of? ( String ) ? value . strip : value html_options [ :data ] . update ( Hash [ name , value ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Header which is a component [CODESPLIT] def header content = nil , options = nil , html_options = nil , & block if is_tap ( content , options ) @header = UiBibz :: Ui :: Ux :: Containers :: Components :: PanelHeader . new ( content , options , html_options ) . tap ( block ) . render else @header = UiBibz :: Ui :: Ux :: Containers :: Components :: PanelHeader . new ( content , options , html_options , block ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Header which is a component [CODESPLIT] def footer content = nil , options = nil , html_options = nil , & block if is_tap ( content , options ) @footer = UiBibz :: Ui :: Ux :: Containers :: Components :: PanelFooter . new ( content , options , html_options ) . tap ( block ) . render else @footer = UiBibz :: Ui :: Ux :: Containers :: Components :: PanelFooter . new ( content , options , html_options , block ) . render end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "header use i18n [CODESPLIT] def header column , name = nil @column = column defaults = [ translate_headers_by_defaults , translate_headers_by_defaults_active_record , translate_headers_by_active_record , header_name ( name ) ] @name = UiBibz :: Utils :: Internationalization . new ( translate_headers_by_model , default : defaults ) . translate sortable? ? sortable_link : title end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See UiBibz :: Ui :: Core :: Boxes :: Card . initialize Render html tag [CODESPLIT] def pre_render init_components content_tag :div , html_options do form_tag ( url_for ( url_parameters ) , method : :get ) do store . parameters . with_indifferent_access . reject { | k , v | default_parameters? ( k ) || v . blank? } . each do | k , v | concat tag ( :input , type : 'hidden' , name : k , value : v ) end concat tag ( :input , type : 'hidden' , name : 'store_id' , value : store . id ) unless store . id . nil? # if there is more one table in html page concat @items . join . html_safe end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add column in table [CODESPLIT] def column data_index = nil , options = nil , html_options = nil , & block @columns << Column . new ( data_index , options , html_options , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add link action in table [CODESPLIT] def link content = nil , options = nil , html_options = nil , & block @actions << UiBibz :: Ui :: Core :: Forms :: Dropdowns :: Components :: DropdownLink . new ( content , options , html_options , block ) . render end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create an Rails plugin engine for documentation site [CODESPLIT] def engine_scaffold FileUtils . mkdir_p ( @gem_temp ) Dir . chdir ( @gem_temp ) do response = Open3 . capture3 ( \"rails plugin new #{gem} --mountable --dummy-path=site --skip-test-unit\" ) if ! response [ 1 ] . empty? puts response [ 1 ] abort \"FAILED: Please be sure you have the rails gem installed with `gem install rails`\" end # Remove files and directories that are unnecessary for the # light-weight Rails documentation site remove = %w( mailers models assets channels jobs views ) . map { | f | File . join ( 'app' , f ) } remove . concat %w( cable.yml storage.yml database.yml ) . map { | f | File . join ( 'config' , f ) } remove . each { | f | FileUtils . rm_rf File . join ( @gem , 'site' , f ) , secure : true } end engine_copy end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy parts of the engine scaffold into site directory [CODESPLIT] def engine_copy site_path = File . join path , 'site' FileUtils . mkdir_p site_path ## Copy Rails plugin files Dir . chdir \"#{@gem_temp}/#{gem}/site\" do %w( app config bin config.ru Rakefile public log ) . each do | item | target = File . join site_path , item FileUtils . cp_r item , target action_log \"create\" , target . sub ( @cwd + '/' , '' ) end end # Remove temp dir FileUtils . rm_rf @gem_temp end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "reports [CODESPLIT] def z_report_session device . session ( \"Z Report\" ) do | s | s . notify \"Z Report Start\" s . fsend Closure :: DAY_FIN_REPORT , \"0\" s . notify \"Z Report End\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If underscore keys copy children to top level vars too Input : _colors : yellow : #fco Output : colors : { yellow : #fco } yellow : #fco [CODESPLIT] def promote_keys ( data ) data . keys . select { | k | k . start_with? ( '_' ) } . each do | key | data [ key . sub ( / / , '' ) ] = data [ key ] data = data . delete ( key ) . merge ( data ) end data end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert [CODESPLIT] def convert_to_sass_value ( item ) if item . is_a? Array make_list ( item ) elsif item . is_a? Hash make_map ( item ) else item . to_s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert hashes to Sass map syntax [CODESPLIT] def make_map ( item ) '(' + item . map { | key , value | key . to_s + ':' + convert_to_sass_value ( value ) } . join ( ',' ) + ')' end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "basket [CODESPLIT] def sale_and_pay_items_session ( items = [ ] , operator = \"1\" , password = \"1\" ) device . session ( \"Fiscal Doc\" ) do | s | s . notify \"Fiscal Doc Start\" s . open_fiscal_doc s . notify \"Register Sale\" items . each do | item | s . add_sale ( item ) end s . notify \"Register Payment\" s . total_payment s . notify \"Close Fiscal Receipt\" s . close_fiscal_doc s . notify \"Fiscal Doc End\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "alias_method : print : push [CODESPLIT] def print ( text ) if device . encoding . present? push text . encode ( device . encoding ) else push text end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "reports [CODESPLIT] def z_report_session device . session ( \"Z Report\" ) do | s | s . notify \"Z Report Start\" s . fsend Reports :: DAILY_REPORT , FLAG_TRUE status = s . get_printer_status s . notify \"Z Report End\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def build_sale_data ( price text1 = text2 = nil tax_group = 2 qty = 1 percent = nil neto = nil number = nil ) [CODESPLIT] def build_sale_data ( sale_item ) \"\" . b . tap ( ) do | data | price_units = ( sale_item . price * 100 ) . to_i # !FIXME price_bytes = \"\" . b 4 . times { | shift | price_bytes . insert 0 , ( ( price_units >> shift 8 ) & 0xff ) . chr } data << price_bytes qty_units = ( ( sale_item . qty || 1 ) * 1000 ) . to_i # !FIXME qty_bytes = \"\" . b 4 . times { | shift | qty_bytes . insert 0 , ( ( qty_units >> shift 8 ) & 0xff ) . chr } data << qty_bytes data << \"\\x00\" . b #number len FIXME data << \"\\xAA\\xAA\\xAA\\xAA\\xAA\\xAA\" . b #number FIXME text = sale_item . text1 . truncate ( 20 ) data << text . length . chr data << text . ljust ( 20 , \" \" ) . b data << ( sale_item . tax_group || 2 ) . chr end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST / devices [CODESPLIT] def create @device = extfaceable . extface_devices . new ( device_params ) if @device . save redirect_to @device , notice : 'Device was successfully created.' else render action : :form end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Rails :: Engine [CODESPLIT] def create_engine ( & block ) @engine = parent_module . const_set ( 'Engine' , Class . new ( Rails :: Engine ) do def spark_plugin_path parent = Object . const_get ( self . class . name . sub ( / / , '' ) ) Pathname . new parent . instance_variable_get ( \"@gem_path\" ) end def config @config ||= Rails :: Engine :: Configuration . new ( spark_plugin_path ) end engine_name SparkEngine . plugin . name require 'spark_engine/middleware' # Ensure compiled assets in /public are served initializer \"#{name}.static_assets\" do | app | if app . config . public_file_server . enabled app . middleware . insert_after :: ActionDispatch :: Static , SparkEngine :: StaticAssets , \"#{root}/public\" , engine_name : SparkEngine . plugin . name app . middleware . insert_before :: ActionDispatch :: Static , Rack :: Deflater end end initializer \"#{name}.view_paths\" do | app | # Ensure Components are readable from engine paths ActiveSupport . on_load :action_controller do append_view_path \"#{SparkEngine.plugin.paths[:components]}\" end end initializer \"#{name}.asset_paths\" do | app | app . config . assets . paths << SparkEngine . plugin . paths [ :components ] end end ) # Autoload engine lib and components path @engine . config . autoload_paths . concat [ File . join ( @engine . spark_plugin_path , \"lib\" ) , SparkEngine . plugin . paths [ :components ] ] @engine . config . after_initialize do | app | if defined? ( SassC ) && defined? ( SassC :: Rails ) # Inject Sass importer for yaml files require \"spark_engine/sassc/importer\" SassC :: Rails :: Importer :: EXTENSIONS << SassC :: SparkEngine :: Importer :: SassYamlExtension . new elsif defined? ( Sass ) # Overwrite Sass engine with Yaml support require \"spark_engine/sass/engine\" end end # Takes a block passed an evaluates it in the context of a Rails engine # This allows plugins to modify engines when created. @engine . instance_eval ( block ) if block_given? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find files based on class type and return an array of Classes for each file [CODESPLIT] def add_files ( klass ) ext = asset_ext klass find_files ( ext ) . map do | path | klass . new ( self , path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find files by class type and extension [CODESPLIT] def find_files ( ext ) files = Dir [ File . join ( paths [ ext . to_sym ] , asset_glob ( ext ) ) ] # Filter out partials files . reject { | f | File . basename ( f ) . start_with? ( '_' ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert configuration into instance variables [CODESPLIT] def set_instance ( name , value ) instance_variable_set ( \"@#{name}\" , value ) instance_eval ( <<-EOS , __FILE__ , __LINE__ + 1 ) #{ name } #{ name } EOS end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Handles running threaded commands [CODESPLIT] def dispatch ( command , * args ) @threads = [ ] send command , args @threads . each { | thr | thr . join } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build assets [CODESPLIT] def build ( options = { } ) puts SparkEngine . production? ? 'Building for production…' : ' uilding…' require_rails clean if SparkEngine . production? SparkEngine . plugin . build ( options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Watch assets for changes and build [CODESPLIT] def watch ( options = { } ) build ( options ) require 'listen' trap ( \"SIGINT\" ) { puts \"\\nspark_engine watcher stopped. Have a nice day!\" exit! } @threads . concat SparkEngine . load_plugin . watch ( options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "todo / fix : pass in known_grounds as a parameter? why? why not? todo / fix : remove = nil in para - make param required w / o fallback [CODESPLIT] def map_ground! ( line , known_grounds = nil ) if known_grounds . nil? puts \"depreciated API call map_ground! (pass in mapping table as 2nd param)\" known_grounds = @known_grounds end TextUtils . map_titles_for! ( 'ground' , line , known_grounds ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "todo / fix : remove = nil in para - make param required w / o fallback [CODESPLIT] def map_person! ( line , known_persons = nil ) if known_persons . nil? puts \"depreciated API call map_person! (pass in mapping table as 2nd param)\" known_persons = @known_persons end TextUtils . map_titles_for! ( 'person' , line , known_persons ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method find_rsssf_scores! [CODESPLIT] def find_rsssf_date! ( line , opts = { } ) finder = RsssfDateFinder . new finder . find! ( line , opts ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method find_rsssf_round! [CODESPLIT] def parse_round_header ( line ) ## todo/fix:\r ##   simplify - for now round number always required\r #      e.g. no auto-calculation supported here\r #       fail if round found w/o number/pos !!!\r #\r #  also remove knockout flag for now (set to always false for now)\r logger . debug \"parsing round header line: >#{line}<\" ## check for date in header first e.g. Round 36 [Jul 20]  !!\r ##   avoid \"conflict\" with getting \"wrong\" round number from date etc.\r date = find_rsssf_date! ( line , start_at : @event . start_at ) if date @last_date = date end title , pos = find_rsssf_round! ( line ) ## check if pos available; if not auto-number/calculate\r if pos . nil? logger . error ( \"  no round pos found in line >#{line}<; round pos required in rsssf; sorry\" ) fail ( \"round pos required in rsssf; sorry\" ) end logger . debug \"  line: >#{line}<\" ## Note: dummy/placeholder start_at, end_at date\r ##  replace/patch after adding all games for round\r round_attribs = { title : title , title2 : nil , knockout : false } round = Round . find_by ( event_id : @event . id , pos : pos ) if round . present? logger . debug \"update round #{round.id}:\" else logger . debug \"create round:\" round = Round . new round_attribs = round_attribs . merge ( { event_id : @event . id , pos : pos , ##  todo: add num e.g. num == pos for round 1, round 2, etc. - why? why not??\r start_at : Date . parse ( '1911-11-11' ) , end_at : Date . parse ( '1911-11-11' ) } ) end logger . debug round_attribs . to_json round . update_attributes! ( round_attribs ) ### store list of round ids for patching start_at/end_at at the end\r @patch_round_ids << round . id @last_round = round ## keep track of last seen round for matches that follow etc.\r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "todo : allow all - in - one literal form a la kicker e . g . 2 : 2 ( 1 : 1 1 : 0 ) n . V . 5 : 1 i . E . [CODESPLIT] def find! ( line , opts = { } ) ### fix: add and match all-in-one literal first, followed by # note: always call after find_dates !!! #  scores match date-like patterns!!  e.g. 10-11  or 10:00 etc. #   -- note: score might have two digits too ### fix: depending on language allow 1:1 or 1-1 ##   do NOT allow mix and match ##  e.g. default to en is  1-1 ##    de is 1:1 etc. # extract score from line # and return it # note: side effect - removes date from line string score1i = nil # half time (ht) scores score2i = nil score1 = nil # full time (ft) scores score2 = nil score1et = nil # extra time (et) scores score2et = nil score1p = nil # penalty (p) scores score2p = nil if ( md = EN__P_ET_FT_HT__REGEX . match ( line ) ) score1i = md [ :score1i ] . to_i score2i = md [ :score2i ] . to_i score1 = md [ :score1 ] . to_i score2 = md [ :score2 ] . to_i score1et = md [ :score1et ] . to_i score2et = md [ :score2et ] . to_i score1p = md [ :score1p ] . to_i score2p = md [ :score2p ] . to_i logger . debug \"   score.en__p_et_ft_ht: >#{score1p}-#{score2p} pen. #{score1et}-#{score2et} a.e.t. (#{score1}-#{score2}, #{score1i}-#{score2i})<\" line . sub! ( md [ 0 ] , '[SCORES.EN__P_ET_FT_HT]' ) elsif ( md = EN__ET_FT_HT__REGEX . match ( line ) ) score1i = md [ :score1i ] . to_i score2i = md [ :score2i ] . to_i score1 = md [ :score1 ] . to_i score2 = md [ :score2 ] . to_i score1et = md [ :score1et ] . to_i score2et = md [ :score2et ] . to_i logger . debug \"   score.en__et_ft_ht: >#{score1et}-#{score2et} a.e.t. (#{score1}-#{score2}, #{score1i}-#{score2i})<\" line . sub! ( md [ 0 ] , '[SCORES.EN__ET_FT_HT]' ) elsif ( md = EN__FT_HT__REGEX . match ( line ) ) score1i = md [ :score1i ] . to_i score2i = md [ :score2i ] . to_i score1 = md [ :score1 ] . to_i score2 = md [ :score2 ] . to_i logger . debug \"   score.en__ft_ht: >#{score1}-#{score2} (#{score1i}-#{score2i})<\" line . sub! ( md [ 0 ] , '[SCORES.EN__FT_HT]' ) else ####################################################### ## try \"standard\" generic patterns for fallbacks if ( md = ET_REGEX . match ( line ) ) score1et = md [ :score1 ] . to_i score2et = md [ :score2 ] . to_i logger . debug \"   score.et: >#{score1et}-#{score2et}<\" line . sub! ( md [ 0 ] , '[SCORE.ET]' ) end if ( md = P_REGEX . match ( line ) ) score1p = md [ :score1 ] . to_i score2p = md [ :score2 ] . to_i logger . debug \"   score.p: >#{score1p}-#{score2p}<\" line . sub! ( md [ 0 ] , '[SCORE.P]' ) end ## let full time (ft) standard regex go last - has no marker if ( md = FT_REGEX . match ( line ) ) score1 = md [ :score1 ] . to_i score2 = md [ :score2 ] . to_i logger . debug \"   score: >#{score1}-#{score2}<\" line . sub! ( md [ 0 ] , '[SCORE]' ) end end ## todo: how to handle game w/o extra time #   but w/ optional penalty ???  e.g. used in copa liberatores, for example #    retrun 0,0 or nil,nil for extra time score ?? or -1, -1 ?? #    for now use nil,nil scores = [ ] scores += [ score1i , score2i ] if score1p || score2p || score1et || score2et || score1 || score2 || score1i || score2i scores += [ score1 , score2 ] if score1p || score2p || score1et || score2et || score1 || score2 scores += [ score1et , score2et ] if score1p || score2p || score1et || score2et scores += [ score1p , score2p ] if score1p || score2p scores end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method load_fixtures [CODESPLIT] def handle_round ( round_pos_str ) round_pos = round_pos_str . to_i round_attribs = { } round = Round . find_by ( event_id : @event . id , pos : round_pos ) if round . present? logger . debug \"update round #{round.id}:\" else logger . debug \"create round:\" round = Round . new round_attribs = round_attribs . merge ( { event_id : @event . id , pos : round_pos , title : \"Round #{round_pos}\" , title2 : nil , knockout : false , start_at : Date . parse ( '1911-11-11' ) , end_at : Date . parse ( '1911-11-11' ) } ) end logger . debug round_attribs . to_json round . update_attributes! ( round_attribs ) ### store list of round ids for patching start_at/end_at at the end\r @patch_round_ids << round . id @last_round = round ## keep track of last seen round for matches that follow etc.\r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method handle_game [CODESPLIT] def parse_fixtures CSV . parse ( @text , headers : true ) do | row | puts row . inspect pp round = row [ 'Round' ] pp date = row [ 'Date' ] pp team1 = row [ 'Team 1' ] pp team2 = row [ 'Team 2' ] pp ft = row [ 'FT' ] pp ht = row [ 'HT' ] ## find round by pos\r if round handle_round ( round ) handle_game ( date , team1 , team2 , ft , ht ) else fail \"round required for import; sorry\" end end ###########################\r # backtrack and patch round dates (start_at/end_at)\r unless @patch_round_ids . empty? ###\r # note: use uniq - to allow multiple round headers (possible?)\r Round . find ( @patch_round_ids . uniq ) . each do | r | logger . debug \"patch round start_at/end_at date for #{r.title}:\" ## note:\r ## will add \"scope\" pos first e.g\r #\r ## SELECT \"games\".* FROM \"games\"  WHERE \"games\".\"round_id\" = ?\r # ORDER BY pos, play_at asc  [[\"round_id\", 7]]\r #   thus will NOT order by play_at but by pos first!!!\r # =>\r #  need to unscope pos!!! or use unordered_games - games_by_play_at_date etc.??\r #   thus use reorder()!!! - not just order('play_at asc')\r games = r . games . reorder ( 'play_at asc' ) . all ## skip rounds w/ no games\r ## todo/check/fix: what's the best way for checking assoc w/ 0 recs?\r next if games . size == 0 # note: make sure start_at/end_at is date only (e.g. use play_at.to_date)\r #   sqlite3 saves datetime in date field as datetime, for example (will break date compares later!)\r round_attribs = { start_at : games [ 0 ] . play_at . to_date , # use games.first ?\r end_at : games [ - 1 ] . play_at . to_date # use games.last ? why? why not?\r } logger . debug round_attribs . to_json r . update_attributes! ( round_attribs ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method run [CODESPLIT] def load_fixtures_with_include_path ( name , include_path ) # load from file system path = \"#{include_path}/#{name}.rb\" puts \"*** loading data '#{name}' (#{path})...\" ## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark) ## - see sportdb/utils.rb code = File . read_utf8 ( path ) load_fixtures_worker ( code ) Prop . create! ( key : \"db.#{fixture_name_to_prop_key(name)}.version\" , value : \"file.rb.#{File.mtime(path).strftime('%Y.%m.%d')}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fix / todo : check that [ ROUND . TITLE2 ] and friends do NOT use pipes ( | ) change all pipes ( | ) to dot ( . ) - pipes get used for def markers!!! [CODESPLIT] def find_round_header_title2! ( line ) ## todo/fix:\r ##  cleanup method\r ##   use  buf.index( '//' ) to split string (see found_round_def)\r ##     why? simpler why not?\r ##  - do we currently allow groups if title2 present? add example if it works?\r # assume everything after // is title2 - strip off leading n trailing whitespaces\r regex = / \\/ \\s \\s / if line =~ regex logger . debug \"   title2: >#{$1}<\" line . sub! ( regex , '[ROUND.TITLE2]' ) return $1 else return nil # no round title2 found (title2 is optional)\r end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method load_fixtures [CODESPLIT] def parse_group_header ( line ) logger . debug \"parsing group header line: >#{line}<\" # note: group header resets (last) round  (allows, for example): #  e.g. #  Group Playoffs/Replays       -- round header #    team1 team2                -- match #  Group B:                     -- group header #    team1 team2 - match  (will get new auto-matchday! not last round) @round = nil ## fix: change/rename to @last_round !!! title , pos = find_group_title_and_pos! ( line ) logger . debug \"    title: >#{title}<\" logger . debug \"    pos: >#{pos}<\" logger . debug \"  line: >#{line}<\" # set group for games @group = Group . find_by_event_id_and_pos! ( @event . id , pos ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method parse_goals = begin ###### add to person and use!!! def self . create_or_update_from_values ( values more_attribs = {} ) ## key & title required [CODESPLIT] def parse_fixtures ( reader ) reader . each_line do | line | if is_goals? ( line ) parse_goals ( line ) elsif is_round_def? ( line ) ## todo/fix:  add round definition (w begin n end date) ## todo: do not patch rounds with definition (already assume begin/end date is good) ##  -- how to deal with matches that get rescheduled/postponed? parse_round_def ( line ) elsif is_round? ( line ) parse_round_header ( line ) elsif is_group_def? ( line ) ## NB: group goes after round (round may contain group marker too) ### todo: add pipe (|) marker (required) parse_group_def ( line ) elsif is_group? ( line ) ##  -- lets you set group  e.g. Group A etc. parse_group_header ( line ) elsif try_parse_game ( line ) # do nothing here elsif try_parse_date_header ( line ) # do nothing here else logger . info \"skipping line (no match found): >#{line}<\" end end # lines.each ########################### # backtrack and patch round pos and round dates (start_at/end_at) #  note: patch dates must go first! (otherwise sort_by_date will not work for round pos) unless @patch_round_ids_dates . empty? ### #  fix: do NOT patch if auto flag is set to false !!! #   e.g. rounds got added w/ round def (not w/ round header) # note: use uniq - to allow multiple round headers (possible?) Round . find ( @patch_round_ids_dates . uniq ) . each do | r | logger . debug \"patch round start_at/end_at date for #{r.title}:\" ## note: ## will add \"scope\" pos first e.g # ## SELECT \"games\".* FROM \"games\"  WHERE \"games\".\"round_id\" = ? # ORDER BY pos, play_at asc  [[\"round_id\", 7]] #   thus will NOT order by play_at but by pos first!!! # => #  need to unscope pos!!! or use unordered_games - games_by_play_at_date etc.?? #   thus use reorder()!!! - not just order('play_at asc') games = r . games . reorder ( 'play_at asc' ) . all ## skip rounds w/ no games ## todo/check/fix: what's the best way for checking assoc w/ 0 recs? next if games . size == 0 # note: make sure start_at/end_at is date only (e.g. use play_at.to_date) #   sqlite3 saves datetime in date field as datetime, for example (will break date compares later!) round_attribs = { start_at : games [ 0 ] . play_at . to_date , # use games.first ? end_at : games [ - 1 ] . play_at . to_date # use games.last ? why? why not? } logger . debug round_attribs . to_json r . update_attributes! ( round_attribs ) end end unless @patch_round_ids_pos . empty? # step 0: check for offset (last_round_pos) if @last_round_pos offset = @last_round_pos logger . info \"  +++ patch round pos - use offset; start w/ #{offset}\" else offset = 0 logger . debug \"  patch round pos - no offset; start w/ 0\" end # step 1: sort by date # step 2: update pos # note: use uniq - to allow multiple round headers (possible?) Round . order ( 'start_at asc' ) . find ( @patch_round_ids_pos . uniq ) . each_with_index do | r , idx | # note: starts counting w/ zero(0) logger . debug \"[#{idx+1}] patch round pos >#{offset+idx+1}< for #{r.title}:\" round_attribs = { pos : offset + idx + 1 } # update title if Matchday XXXX  e.g. use Matchday 1 etc. if r . title . starts_with? ( 'Matchday' ) round_attribs [ :title ] = \"Matchday #{offset+idx+1}\" end logger . debug round_attribs . to_json r . update_attributes! ( round_attribs ) # update last_round_pos offset too @last_round_pos = [ offset + idx + 1 , @last_round_pos || 0 ] . max end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "e . g . cut_off_end_of_line_comment! [CODESPLIT] def find! ( line , opts = { } ) # remove end-of-line comments\r #   - move to textutils ?? why? why not??\r cut_off_end_of_line_comment! ( line ) ## note: func defined in utils.rb (FixtureHelpers)\r # remove [] if presents e.g. [Neymar 12']\r line = line . gsub ( / \\[ \\] / , '' ) # remove (single match) if line starts w/ - (allow spaces)  e.g. [-;Neymar 12'] or [ - ;Neymar 12']\r line = line . sub ( / / , '' ) # split into left hand side (lhs) for team1 and\r #            right hand side (rhs) for team2\r values = line . split ( ';' ) # note: allow empty right hand side (e.g. team2 did NOT score any goals e.g. 3-0 etc.)\r lhs = values [ 0 ] rhs = values [ 1 ] lhs = lhs . strip unless lhs . nil? rhs = rhs . strip unless rhs . nil? parser = GoalsParser . new ## todo/check: only call if not nil?\r logger . debug \"  lhs (team1): >#{lhs}<\" lhs_data = parser . parse! ( lhs ) pp lhs_data logger . debug \"  rhs (team2): >#{rhs}<\" rhs_data = parser . parse! ( rhs ) pp rhs_data ### merge into flat goal structs\r goals = [ ] lhs_data . each do | player | player . minutes . each do | minute | goal = GoalStruct . new goal . name = player . name goal . team = 1 goal . minute = minute . minute goal . offset = minute . offset goal . penalty = minute . penalty goal . owngoal = minute . owngoal goals << goal end end rhs_data . each do | player | player . minutes . each do | minute | goal = GoalStruct . new goal . name = player . name goal . team = 2 goal . minute = minute . minute goal . offset = minute . offset goal . penalty = minute . penalty goal . owngoal = minute . owngoal goals << goal end end # sort by minute + offset\r goals = goals . sort do | l , r | res = l . minute <=> r . minute if res == 0 res = l . offset <=> r . offset # pass 2: sort by offset\r end res end ## calc score1,score2\r score1 = 0 score2 = 0 goals . each do | goal | if goal . team == 1 score1 += 1 elsif goal . team == 2 score2 += 1 else # todo: should not happen: issue warning\r end goal . score1 = score1 goal . score2 = score2 end logger . debug \"  #{goals.size} goals:\" pp goals goals end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method find_files [CODESPLIT] def patch ( save = false ) files = find_files change_logs = [ ] files . each do | file | p = PrettyPrinter . from_file ( file ) new_text , change_log = p . patch next if change_log . empty? ## no changes if save File . open ( file , 'w' ) do | f | f . write new_text end end change_logs << [ file , change_log ] end change_logs ## return change_logs or empty array end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "lets us use match_teams_for_country etc . [CODESPLIT] def load_setup ( name ) reader = create_fixture_reader ( name ) reader . each do | fixture_name | load ( fixture_name ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method load_setup [CODESPLIT] def load ( name ) # convenience helper for all-in-one reader\r logger . debug \"enter load( name=>>#{name}<<)\" ## formerly also printed -> include_path=>>#{include_path}<<\r if match_players_for_country ( name ) do | country_key | ## country = Country.find_by_key!( country_key )\r ## fix-fix-fix-fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!\r ## reader = PersonDb::PersonReader.new( include_path )\r ## reader.read( name, country_id: country.id )\r end elsif name =~ / \\/ \\/ / # e.g. ajax.txt bayern.txt etc.\r ## note: for now assume club (e.g. no dash (-) allowed for country code e.g. br-brazil etc.)\r team = Team . find_by_key! ( $1 ) ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)\r reader = create_club_squad_reader ( name , team_id : team . id , event_id : @event . id ) reader . read ( ) elsif name =~ / \\/ \\/ \\/ / ## fix: add to country matcher new format\r ##   name is country! and parent folder is type name e.g. /squads/br-brazil\r # note: if two letters, assume country key\r #       if three letters, assume team key\r ##   allow three letter codes\r ##  assume three letter code are *team* codes (e.g. fdr, gdr, etc)\r ##      not country code (allows multiple teams per country)\r if $1 . length == 2 ## get national team via country\r country = Country . find_by_key! ( $1 ) ###  for now assume country code matches team for now (do NOT forget to downcase e.g. BRA==bra)\r logger . info \"  assume country code == team code for #{country.code}\" team = Team . find_by_key! ( country . code . downcase ) else # assume length == 3\r ## get national team directly (use three letter fifa code)\r team = Team . find_by_key! ( $1 ) end ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)\r reader = create_national_team_squad_reader ( name , team_id : team . id , event_id : @event . id ) reader . read ( ) elsif name =~ / \\/ / # NB: ^seasons or also possible at-austria!/seasons\r reader = create_season_reader ( name ) reader . read ( ) elsif name =~ / \\/ / # NB: ^assocs or also possible national-teams!/assocs\r reader = create_assoc_reader ( name ) reader . read ( ) elsif match_stadiums_for_country ( name ) do | country_key | country = Country . find_by_key! ( country_key ) reader = create_ground_reader ( name , country_id : country . id ) reader . read ( ) end elsif match_leagues_for_country ( name ) do | country_key | # name =~ /^([a-z]{2})\\/leagues/\r # auto-add country code (from folder structure) for country-specific leagues\r #  e.g. at/leagues\r country = Country . find_by_key! ( country_key ) reader = create_league_reader ( name , club : true , country_id : country . id ) reader . read ( ) end elsif name =~ / \\/ / # NB: ^leagues or also possible world!/leagues  - NB: make sure goes after leagues_for_country!!\r reader = create_league_reader ( name ) reader . read ( ) elsif match_teams_for_country ( name ) do | country_key | # name =~ /^([a-z]{2})\\/teams/\r # auto-add country code (from folder structure) for country-specific teams\r #  e.g. at/teams at/teams.2 de/teams etc.\r country = Country . find_by_key! ( country_key ) reader = create_team_reader ( name , country_id : country . id ) reader . read ( ) end elsif match_clubs_for_country ( name ) do | country_key | # name =~ /^([a-z]{2})\\/clubs/\r # auto-add country code (from folder structure) for country-specific clubs\r #  e.g. at/teams at/teams.2 de/teams etc.                \r country = Country . find_by_key! ( country_key ) reader = create_team_reader ( name , club : true , country_id : country . id ) ## note: always sets club flag to true\r reader . read ( ) end elsif name =~ / \\/ / ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ???\r ### fix: use new NationalTeamReader ??? why? why not?\r reader = create_team_reader ( name ) ## note: always sets club flag to true / national to true\r reader . read ( ) elsif name =~ / \\/ / ### fix: use new ClubReader ??? why? why not?\r reader = create_team_reader ( name , club : true ) ## note: always sets club flag to true / national to false\r reader . read ( ) elsif name =~ / \\. / ## e.g.  1-premierleague.conf  => 1-premierleague.conf.txt\r reader = create_event_table_reader ( name ) reader . read ( ) # note: keep a \"public\" reference of last event in @event  - e.g. used/required by squads etc.\r @event = reader . event elsif name =~ / \\/ \\d \\d \\- \\d \\/ \\/ / || name =~ / \\/ \\d \\d \\- \\d / # note: allow 2013_14 or 2013-14 (that, is dash or underscore)\r # e.g. must match /2012/ or /2012_13/  or   /2012--xxx/ or /2012_13--xx/\r #  or   /2012 or /2012_13   e.g. brazil/2012 or brazil/2012_13\r reader = create_game_reader ( name ) reader . read ( ) # note: keep a \"public\" reference of last event in @event  - e.g. used/required by squads etc.\r @event = reader . event else logger . error \"unknown sportdb fixture type >#{name}<\" # todo/fix: exit w/ error\r end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "replace_images newer versions of LibreOffice can t open files with duplicates image names [CODESPLIT] def avoid_duplicate_image_names ( content ) nodes = content . xpath ( \"//draw:frame[@draw:name]\" ) nodes . each_with_index do | node , i | node . attribute ( 'name' ) . value = \"pic_#{i}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the hash of the key and value specified for the scope . [CODESPLIT] def scope_params return { } if dynamic_scaffold . scope . nil? case dynamic_scaffold . scope when Array then dynamic_scaffold . scope . each_with_object ( { } ) do | val , res | if val . is_a? Hash val . each { | k , v | res [ k ] = v } else res [ val ] = params [ val ] end end when Hash then dynamic_scaffold . scope end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert pkey_string value to hash . [CODESPLIT] def pkey_string_to_hash ( pkey ) # https://github.com/gomo/dynamic_scaffold/pull/9/commits/ff5de0e38b3544347e82539c45ffd2efaf3410da # Stop support multiple pkey, on this commit. # Convert \"key:1,code:foo\" to {key: \"1\", code: \"foo\"} pkey . split ( ',' ) . map { | v | v . split ( ':' ) } . each_with_object ( { } ) { | v , res | res [ v . first ] = v . last } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get paramters for sort action . pkeys [] [ column ] = > value [CODESPLIT] def sort_params params . require ( 'pkeys' ) . map { | p | p . permit ( dynamic_scaffold . model . primary_key ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get paramters for update record . [CODESPLIT] def update_values # rubocop:disable Metrics/AbcSize # set the parameters of carrierwave_image at the end for validates. permitting = [ ] dynamic_scaffold . form . items . reject { | i | i . type? ( :carrierwave_image ) } . each do | item | item . extract_parameters ( permitting ) end permitting . concat ( dynamic_scaffold . form . permit_params ) dynamic_scaffold . form . items . select { | i | i . type? ( :carrierwave_image ) } . each do | item | item . extract_parameters ( permitting ) end values = params . require ( dynamic_scaffold . model . name . underscore ) . permit ( permitting ) if dynamic_scaffold . scope && ! valid_for_scope? ( values ) raise DynamicScaffold :: Error :: InvalidOperation , \"You can update only to #{scope_params} on this scope\" end values end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if there are inconsistent scopes in update parameters [CODESPLIT] def valid_for_scope? ( update_params ) return true if dynamic_scaffold . scope_options [ :changeable ] result = true scope_params . each do | key , value | if update_params . key? ( key ) && update_params [ key ] != value result = false break end end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Actions [CODESPLIT] def index # rubocop:disable Metrics/AbcSize @records = dynamic_scaffold . list . build_sql ( scope_params ) @count = @records . count unless dynamic_scaffold . max_count . nil? @records = handle_pagination ( @records ) @records = @records . order dynamic_scaffold . list . sorter if dynamic_scaffold . list . sorter @records = @records . order ( dynamic_scaffold . list . order ) unless dynamic_scaffold . list . order . empty? ret = yield ( @records ) if block_given? @records = ret unless ret . nil? unless @records . is_a? :: ActiveRecord :: Relation raise ( Error :: InvalidOperation , 'You must return ActiveRecord::Relation from super block' ) end @records end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "number tokens are added to the bucket every period seconds ( up to a max of number tokens being available ) . Each time a resource is used a token is removed from the bucket ; if no tokens are available no resource may be used . [CODESPLIT] def take took = @redis . with do | conn | RedisLocks . evalsha_or_eval ( conn : conn , script : SCRIPT , digest : DIGEST , keys : [ @key ] , args : [ epoch_f ( conn ) , @rps , @burst ] ) end took == 1 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Acquire a resource from the semaphore if available . Returns false if no resources are available . [CODESPLIT] def lock ( timeout : nil , & block ) ensure_exists_and_release_stale_locks! success = @redis . with do | conn | if timeout ! conn . blpop ( available_key , timeout . to_i ) . nil? else ! conn . lpop ( available_key ) . nil? end end return false unless success token = SecureRandom . hex ( 16 ) @tokens . push ( token ) @redis . with do | conn | conn . zadd ( grabbed_key , epoch_f ( conn ) , token ) end return_or_yield ( token , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Release a resource back to the semaphore . Should normally be called with an explicit token . [CODESPLIT] def unlock ( token = @tokens . pop ) return unless token removed = false @redis . with do | conn | removed = conn . zrem grabbed_key , token if removed conn . lpush available_key , 1 end end removed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a notification object . [CODESPLIT] def apply_options ( options = { } ) options . each { | key , value | send ( \"#{key}=\" , value ) if respond_to? ( key ) } yield ( self ) if block_given? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Shows a new notification . [CODESPLIT] def show! notify_init ( app_name ) or raise \"notify_init failed\" raw_ptr = notify_notification_new ( summary , body , icon_path , nil ) @notification = :: FFI :: AutoPointer . new ( raw_ptr , method ( :g_object_unref ) ) show end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates a previously shown notification or creates a new one . [CODESPLIT] def update ( options = { } , & block ) apply_options ( options , block ) if @notification notify_notification_update ( @notification , summary , body , icon_path , nil ) show else show! end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a usable youtube - dl executable ( system or vendor ) [CODESPLIT] def usable_executable_path_for ( exe ) system_path = which ( exe ) if system_path . nil? # TODO: Search vendor bin for executable before just saying it's there. vendor_path = File . absolute_path ( \"#{__FILE__}/../../../vendor/bin/#{exe}\" ) File . chmod ( 775 , vendor_path ) unless File . executable? ( vendor_path ) # Make sure vendor binary is executable vendor_path else system_path . strip end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helper for doing lines of cocaine ( initializing auto executable stuff etc ) [CODESPLIT] def cocaine_line ( command , executable_path = nil ) executable_path = executable_path_for ( 'youtube-dl' ) if executable_path . nil? Cocaine :: CommandLine . new ( executable_path , command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Instantiate new model [CODESPLIT] def download raise ArgumentError . new ( 'url cannot be nil' ) if @url . nil? raise ArgumentError . new ( 'url cannot be empty' ) if @url . empty? set_information_from_json ( YoutubeDL :: Runner . new ( url , runner_options ) . run ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Redirect methods for information getting [CODESPLIT] def method_missing ( method , * args , & block ) value = information [ method ] if value . nil? super else value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parses options and converts them to Cocaine s syntax [CODESPLIT] def options_to_commands commands = [ ] @options . sanitize_keys . each_paramized_key do | key , paramized_key | if @options [ key ] . to_s == 'true' commands . push \"--#{paramized_key}\" elsif @options [ key ] . to_s == 'false' commands . push \"--no-#{paramized_key}\" else commands . push \"--#{paramized_key} :#{key}\" end end commands . push quoted ( url ) commands . join ( ' ' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Merge options with given hash removing banned keys and returning a new instance of Options . [CODESPLIT] def with ( hash ) merged = Options . new ( @store . merge ( hash . to_h ) ) merged . banned_keys = @banned_keys merged . send ( :remove_banned ) merged end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Option getting and setting using ghost methods [CODESPLIT] def method_missing ( method , * args , & _block ) remove_banned if method . to_s . include? '=' method = method . to_s . tr ( '=' , '' ) . to_sym return nil if banned? method @store [ method ] = args . first else return nil if banned? method @store [ method ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calls a block to do operations on keys See sanitize_keys! for examples [CODESPLIT] def manipulate_keys! ( & block ) @store . keys . each do | old_name | new_name = block . call ( old_name ) unless new_name == old_name @store [ new_name ] = @store [ old_name ] @store . delete ( old_name ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Symbolizes and sanitizes keys in the option store [CODESPLIT] def sanitize_keys! # Symbolize manipulate_keys! { | key_name | key_name . is_a? ( Symbol ) ? key_name : key_name . to_sym } # Underscoreize (because Cocaine doesn't like hyphens) manipulate_keys! { | key_name | key_name . to_s . tr ( '-' , '_' ) . to_sym } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allowable options are : - : environment e . g . test - : task . e . g resque : work - : queue e . g . * - : count e . g . 3 - : interval e . g . 5 - : verbose e . g . true - : vverbose e . g . true - : trace e . g . true - : stop_signal e . g . : QUIT or : SIGQUIT [CODESPLIT] def start stop UI . info 'Starting up resque...' UI . info [ cmd , env . map { | v | v . join ( '=' ) } ] . join ( ' ' ) # launch Resque worker @pid = spawn ( env , cmd ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "We pass ourselves as both input and output to Ernicorn . process which calls the following blocking read / write methods . [CODESPLIT] def read ( len ) data = '' while data . bytesize < len data << @client . kgio_read! ( len - data . bytesize ) end data end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TODO : move into separate class so we don t pollute controller . [CODESPLIT] def consume! ( model , options = { } ) content_type = request . content_type format = Mime :: Type . lookup ( content_type ) . try ( :symbol ) or raise UnsupportedMediaType . new ( \"Cannot consume unregistered media type '#{content_type.inspect}'\" ) parsing_method = compute_parsing_method ( format ) representer = prepare_model_for ( format , model , options ) representer . send ( parsing_method , incoming_string , options ) # e.g. from_json(\"...\") model end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Central entry - point for finding the appropriate representer . [CODESPLIT] def representer_for ( format , model , options = { } ) options . delete ( :represent_with ) || self . class . represents_options . for ( format , model , controller_path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Article Show [CODESPLIT] def show @article_post = Phcpress :: Article :: Post . friendly . find ( params [ :id ] ) @versions = Phcpress :: PostVersions . where ( item_id : params [ :id ] , item_type : 'Phcpress::Article::Post' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST [CODESPLIT] def create @article_post = Phcpress :: Article :: Post . new ( article_post_params ) @article_post . user_id = current_user . id @article_post . org_id = current_user . org_id if @article_post . save redirect_to article_posts_url , notice : 'Post was successfully created.' else render :new end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Categories Show [CODESPLIT] def show @article_category = Phcpress :: Article :: Category . friendly . find ( params [ :id ] ) @versions = Phcpress :: CategoryVersions . where ( item_id : params [ :id ] , item_type : 'Phcpress::Article::Category' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST [CODESPLIT] def create @article_category = Phcpress :: Article :: Category . new ( article_category_params ) @article_category . user_id = current_user . id @article_category . org_id = current_user . org_id if @article_category . save redirect_to article_categories_url , notice : 'Category was successfully created.' else render :new end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called when the new method is invoked Sets a variable field that can be recalled [CODESPLIT] def variable_text_field ( x , y , params = { } ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) options = { height : 0.1 , width : 0.1 } . merge! ( params ) # update the variable field count self . variable_fields_count += 1 label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s ) if params [ :orientation ] == :landscape label_data . push ( '^A0N,' ) else label_data . push ( '^A0B,' ) end label_data . push ( Integer ( options [ :height ] * printer_dpi ) . to_s + ',' + Integer ( options [ :width ] * printer_dpi ) . to_s + '^FN' + variable_fields_count . to_s + '^FS' ) # return unless label_height > 0 && label_width > 0 # pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}', #              at: [Integer(x * pdf_dpi), Integer(label_width * pdf_dpi) - #              Integer(y * pdf_dpi) - #              Integer(options[:height] / 10) * pdf_dpi], #              size: Integer(options[:height] * pdf_dpi) if label_height && #              label_width end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the home position of the label All other X and Y coordinates are relative to this [CODESPLIT] def home_position ( x , y ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) label_data . push ( '^LH' + x . to_s + ',' + y . to_s ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws a square border on dot in width [CODESPLIT] def draw_border ( x , y , height , width ) return unless numeric? ( height ) && numeric? ( width ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s + '^GB' + Integer ( height * printer_dpi ) . to_s + ',' + Integer ( width * printer_dpi ) . to_s + ',1^FS' ) # draw_rectangle(x * pdf_dpi, y * pdf_dpi, height * pdf_dpi, width * pdf_dpi) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints text [CODESPLIT] def text_field ( text , x , y , params = { } ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) options = { height : 0.1 , width : 0.1 } . merge! ( params ) label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s ) if params [ :orientation ] == :landscape label_data . push ( '^A0N,' ) else label_data . push ( '^A0B,' ) end label_data . push ( Integer ( options [ :height ] * printer_dpi ) . to_s + ',' + Integer ( options [ :width ] * printer_dpi ) . to_s + '^FD' + text + '^FS' ) # return unless label_height > 0 && label_width > 0 # pdf.text_box text, at: [x, label_width - y - #                    Integer((options[:height] * pdf_dpi) / 10)], #                    size: (options[:height] * #                    pdf_dpi) if label_height && label_width end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a bar code in barcode39 font [CODESPLIT] def bar_code_39 ( bar_code_string , x , y , params = { } ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s + '^B3N,N,20,N,N^FD' + bar_code_string + '^FS' ) # return unless label_height && label_width # options = { height: 20 }.merge!(params) { |key, v1, v2| v1 } # draw_bar_code_39(bar_code_string, Integer(x * pdf_dpi), #                  Integer(y * pdf_dpi), (options[:height] * pdf_dpi)) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a bar code in barcode39 font [CODESPLIT] def bar_code_128 ( bar_code_string , x , y , params = { } ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) height = numeric? ( params [ :height ] ) ? params [ :height ] : 0.2 interpretation = params [ :interpretation ] == :true ? 'Y' : 'N' interpretation_location = params [ :interpretation_location ] == :above ? 'Y' : 'N' check_digit = params [ :check_digit ] == :true ? 'Y' : 'N' mode = { :ucc_case => 'U' , :auto => 'A' , :ucc_ean => 'D' } [ params [ :mode ] ] || 'N' orientation = { :portrait => 'R' , 90 => 'R' , 180 => 'I' , 270 => 'B' } [ params [ :orientation ] ] || 'N' label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s + '^BC' + orientation + ',' + Integer ( height * printer_dpi ) . to_s + ',' + interpretation + ',' + interpretation_location + ',' + check_digit + ',' + mode + '^FD' + bar_code_string + '^FS' ) # return unless label_height && label_width # options = { height: 20 }.merge!(params) { |key, v1, v2| v1 } # draw_bar_code128_(bar_code_string, Integer(x * pdf_dpi), #                   Integer(y * pdf_dpi), (options[:height] * pdf_dpi)) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a bar code in barcode39 font [CODESPLIT] def bar_code_qr ( bar_code_string , x , y , params = { } ) x = 0 unless numeric? ( x ) y = 0 unless numeric? ( y ) magnification = numeric? ( params [ :magnification ] ) ? params [ :magnification ] : default_qr_code_magnification error_correction = { :ultra => 'H' , :high => 'Q' , :standard => 'M' , :density => 'L' } [ params [ :error_correction ] ] || ( params [ :error_correction ] ) . nil? ? 'Q' : 'M' mask = numeric? ( params [ :mask ] ) ? params [ :mask ] : 7 model = { 1 => 1 , :standard => 1 , 2 => 2 , :enhanced => 2 } [ params [ :model ] ] || 2 label_data . push ( '^FO' + Integer ( x * printer_dpi ) . to_s + ',' + Integer ( y * printer_dpi ) . to_s + '^BQN,' + Integer ( model ) . to_s + ',' + Integer ( magnification ) . to_s + ',' + error_correction + ',' + Integer ( mask ) . to_s + '^FD' + error_correction + 'A,' + bar_code_string + '^FS' ) # return unless label_height && label_width # options = { height: 20 }.merge!(params) { |key, v1, v2| v1 } # draw_bar_code128_(bar_code_string, Integer(x * pdf_dpi), #                   Integer(y * pdf_dpi), (options[:height] * pdf_dpi)) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Some barcodes such as QR codes may change document defaults . These may be reset to the document defaults . [CODESPLIT] def reset_barcode_fields_to_default label_data . push ( '^BY' + Integer ( self . barcode_default_module_width ) . to_s + ',' + Float ( self . barcode_default_width_ratio ) . to_s + ',' + Integer ( self . barcode_default_height ) . to_s ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the PDF rectangle ( border ) [CODESPLIT] def draw_rectangle ( x , y , height , width ) return unless label_height > 0 && label_width > 0 pdf . stroke_axis pdf . stroke do pdf . rectangle [ x * pdf_dpi , label_width - ( y * pdf_dpi ) - ( width * pdf_dpi ) ] , height , ( width * pdf_dpi ) * - 1 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Draws the PDF bar code 39 [CODESPLIT] def draw_bar_code_39 ( bar_code_string , x , y , height ) return unless label_height > 0 && label_width > 0 pdf . bounding_box [ x , Integer ( label_width ) - y - ( height * pdf_dpi ) ] , width : ( height * pdf_dpi ) do barcode = Barby :: Code39 . new ( bar_code_string ) barcode . annotate_pdf ( pdf , height : ( height * pdf_dpi ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called when the new method is invoked Adds a variable that is to be applied to the saved template [CODESPLIT] def add_field ( value ) return if value . nil? return if value . strip . empty? # Increment the variable field count self . variable_fields_count += 1 # Add the field label_data . push ( '^FN' + variable_fields_count . to_s + '^FD' + value + '^FS' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds a new slug . [CODESPLIT] def build_slug if localized? begin orig_locale = I18n . locale all_locales . each do | target_locale | I18n . locale = target_locale apply_slug end ensure I18n . locale = orig_locale end else apply_slug end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns true if object is a new record and slugs are present [CODESPLIT] def new_with_slugs? if localized? # We need to check if slugs are present for the locale without falling back # to a default new_record? && _slugs_translations . fetch ( I18n . locale . to_s , [ ] ) . any? else new_record? && _slugs . present? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns true if object has been persisted and has changes in the slug [CODESPLIT] def persisted_with_slug_changes? if localized? changes = _slugs_change return ( persisted? && false ) if changes . nil? # ensure we check for changes only between the same locale original = changes . first . try ( :fetch , I18n . locale . to_s , nil ) compare = changes . last . try ( :fetch , I18n . locale . to_s , nil ) persisted? && original != compare else persisted? && _slugs_changed? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return all possible locales for model Avoiding usage of I18n . available_locales in case the user hasn t set it properly or is doing something crazy but at the same time we need a fallback in case the model doesn t have any localized attributes at all ( extreme edge case ) . [CODESPLIT] def all_locales locales = slugged_attributes . map { | attr | send ( \"#{attr}_translations\" ) . keys if respond_to? ( \"#{attr}_translations\" ) } . flatten . compact . uniq locales = I18n . available_locales if locales . empty? locales end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Assigns the : request_id thread - local variable and cleans up all the request - local variables after the request . [CODESPLIT] def call ( env ) Thread . current [ :request_id ] = extract_request_id ( env ) @app . call ( env ) ensure RequestLocals . clear! Thread . current [ :request_id ] = nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the distance of time in words from the given from_time to the specified to_time . If to_time is not specified then Time . now is used . By default seconds are included ... set the include_seconds argument to false to disable the seconds . [CODESPLIT] def distance_of_time_in_words ( from_time , to_time = Time . now ) from_time = from_time . to_time if from_time . respond_to? ( :to_time ) to_time = to_time . to_time if to_time . respond_to? ( :to_time ) seconds = ( to_time - from_time ) . round distance_in_days = ( seconds / ( 60 * 60 * 24 ) ) . round seconds = seconds % ( 60 * 60 * 24 ) distance_in_hours = ( seconds / ( 60 * 60 ) ) . round seconds = seconds % ( 60 * 60 ) distance_in_minutes = ( seconds / 60 ) . round seconds = seconds % 60 distance_in_seconds = seconds s = '' s << \"#{distance_in_days} days,\" if distance_in_days > 0 s << \"#{distance_in_hours} hours, \" if distance_in_hours > 0 s << \"#{distance_in_minutes} minutes, \" if distance_in_minutes > 0 s << \"#{distance_in_seconds} seconds\" s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the approximate disntance of time in words from the given from_time to the the given to_time . If to_time is not specified then it is set to Time . now . By default seconds are included ... set the include_seconds argument to false to disable the seconds . [CODESPLIT] def approximate_distance_of_time_in_words ( from_time , to_time = Time . now , include_seconds = true ) from_time = from_time . to_time if from_time . respond_to? ( :to_time ) to_time = to_time . to_time if to_time . respond_to? ( :to_time ) distance_in_minutes = ( ( ( to_time - from_time ) . abs ) / 60 ) . round distance_in_seconds = ( ( to_time - from_time ) . abs ) . round case distance_in_minutes when 0 .. 1 return ( distance_in_minutes == 0 ) ? 'less than a minute' : '1 minute' unless include_seconds case distance_in_seconds when 0 .. 4 then 'less than 5 seconds' when 5 .. 9 then 'less than 10 seconds' when 10 .. 19 then 'less than 20 seconds' when 20 .. 39 then 'half a minute' when 40 .. 59 then 'less than a minute' else '1 minute' end when 2 .. 44 then \"#{distance_in_minutes} minutes\" when 45 .. 89 then 'about 1 hour' when 90 .. 1439 then \"about #{(distance_in_minutes.to_f / 60.0).round} hours\" when 1440 .. 2879 then '1 day' when 2880 .. 43199 then \"#{(distance_in_minutes / 1440).round} days\" when 43200 .. 86399 then 'about 1 month' when 86400 .. 525959 then \"#{(distance_in_minutes / 43200).round} months\" when 525960 .. 1051919 then 'about 1 year' else \"over #{(distance_in_minutes / 525960).round} years\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "First attempt at centralizing error notifications [CODESPLIT] def track_error ( control , msg ) errors << msg control . error_handlers . each do | handler | handler . call ( msg ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process a file control object or batch object . Acceptable values for file are : * Path to a file * File object * ETL :: Control :: Control instance * ETL :: Batch :: Batch instance [CODESPLIT] def process ( file ) case file when String process ( File . new ( file ) ) when File case file . path when / \\. \\. / ; process_control ( file ) when / \\. \\. / ; process_batch ( file ) else raise RuntimeError , \"Unsupported file type - #{file.path}\" end when ETL :: Control :: Control process_control ( file ) when ETL :: Batch :: Batch process_batch ( file ) else raise RuntimeError , \"Process object must be a String, File, Control \n        instance or Batch instance\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process the specified batch file [CODESPLIT] def process_batch ( batch ) batch = ETL :: Batch :: Batch . resolve ( batch , self ) say \"Processing batch #{batch.file}\" ETL :: Engine . batch = ETL :: Execution :: Batch . create! ( :batch_file => batch . file , :status => 'executing' ) batch . execute ETL :: Engine . batch . completed_at = Time . now ETL :: Engine . batch . status = ( errors . length > 0 ? 'completed with errors' : 'completed' ) ETL :: Engine . batch . save! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process the specified control file [CODESPLIT] def process_control ( control ) control = ETL :: Control :: Control . resolve ( control ) say_on_own_line \"Processing control #{control.file}\" ETL :: Engine . job = ETL :: Execution :: Job . new . tap do | job | job . control_file = control . file job . status = 'executing' job . batch_id = ETL :: Engine . batch ? ETL :: Engine . batch . id : nil job . save! end execute_dependencies ( control ) start_time = Time . now pre_process ( control ) sources = control . sources destinations = control . destinations say \"Skipping bulk import\" if Engine . skip_bulk_import sources . each do | source | Engine . current_source = source Engine . logger . debug \"Processing source #{source.inspect}\" say \"Source: #{source}\" say \"Limiting enabled: #{Engine.limit}\" if Engine . limit != nil say \"Offset enabled: #{Engine.offset}\" if Engine . offset != nil source . each_with_index do | row , index | # Break out of the row loop if the +Engine.limit+ is specified and  # the number of rows read exceeds that value. if Engine . limit != nil && Engine . rows_read >= Engine . limit puts \"Reached limit of #{Engine.limit}\" break end Engine . logger . debug \"Row #{index}: #{row.inspect}\" Engine . rows_read += 1 Engine . current_source_row = index + 1 say_without_newline \".\" if Engine . realtime_activity && index > 0 && index % 1000 == 0 # At this point a single row may be turned into multiple rows via row  # processors all code after this line should work with the array of  # rows rather than the single row rows = [ row ] t = Benchmark . realtime do begin Engine . logger . debug \"Processing after read\" control . after_read_processors . each do | processor | processed_rows = [ ] rows . each do | row | processed_rows << processor . process ( row ) unless empty_row? ( row ) end rows = processed_rows . flatten . compact end rescue => e msg = \"Error processing rows after read from #{Engine.current_source} on line #{Engine.current_source_row}: #{e}\" # TODO - track more information: row if possible, full exception... track_error ( control , msg ) Engine . logger . error ( msg ) e . backtrace . each { | line | Engine . logger . error ( line ) } exceeded_error_threshold? ( control ) ? break : next end end benchmarks [ :after_reads ] += t unless t . nil? t = Benchmark . realtime do begin Engine . logger . debug \"Executing transforms\" rows . each do | row | # only do the transform if there is a row unless empty_row? ( row ) control . transforms . each do | transform | name = transform . name . to_sym row [ name ] = transform . transform ( name , row [ name ] , row ) end end end rescue ResolverError => e Engine . logger . error ( e . message ) track_error ( control , e . message ) rescue => e msg = \"Error transforming from #{Engine.current_source} on line #{Engine.current_source_row}: #{e}\" track_error ( control , msg ) Engine . logger . error ( msg ) e . backtrace . each { | line | Engine . logger . error ( line ) } ensure begin exceeded_error_threshold? ( control ) ? break : next rescue => inner_error puts inner_error end end end benchmarks [ :transforms ] += t unless t . nil? t = Benchmark . realtime do begin # execute row-level \"before write\" processing Engine . logger . debug \"Processing before write\" control . before_write_processors . each do | processor | processed_rows = [ ] rows . each do | row | processed_rows << processor . process ( row ) unless empty_row? ( row ) end rows = processed_rows . flatten . compact end rescue => e msg = \"Error processing rows before write from #{Engine.current_source} on line #{Engine.current_source_row}: #{e}\" track_error ( control , msg ) Engine . logger . error ( msg ) e . backtrace . each { | line | Engine . logger . error ( line ) } exceeded_error_threshold? ( control ) ? break : next end end benchmarks [ :before_writes ] += t unless t . nil? t = Benchmark . realtime do begin # write the row to the destination destinations . each_with_index do | destination , index | Engine . current_destination = destination rows . each do | row | destination . write ( row ) Engine . rows_written += 1 if index == 0 end end rescue => e msg = \"Error writing to #{Engine.current_destination}: #{e}\" track_error ( control , msg ) Engine . logger . error msg e . backtrace . each { | line | Engine . logger . error ( line ) } exceeded_error_threshold? ( control ) ? break : next end end benchmarks [ :writes ] += t unless t . nil? end if exceeded_error_threshold? ( control ) say_on_own_line \"Exiting due to exceeding error threshold: #{control.error_threshold}\" ETL :: Engine . exit_code = 1 end end destinations . each do | destination | destination . close end say_on_own_line \"Executing before post-process screens\" begin execute_screens ( control ) rescue FatalScreenError => e say \"Fatal screen error during job execution: #{e.message}\" ETL :: Engine . exit_code = 2 rescue ScreenError => e say \"Screen error during job execution: #{e.message}\" return else say \"Screens passed\" end post_process ( control ) if sources . length > 0 say_on_own_line \"Read #{Engine.rows_read} lines from sources\" end if destinations . length > 0 say \"Wrote #{Engine.rows_written} lines to destinations\" end say_on_own_line \"Executing after post-process screens\" begin execute_screens ( control , :after_post_process ) rescue FatalScreenError => e say \"Fatal screen error during job execution: #{e.message}\" ETL :: Engine . exit_code = 3 rescue ScreenError => e say \"Screen error during job execution: #{e.message}\" return else say \"Screens passed\" end say_on_own_line \"Completed #{control.file} in #{distance_of_time_in_words(start_time)} with #{errors.length} errors.\" say \"Processing average: #{Engine.average_rows_per_second} rows/sec)\" say \"Avg after_reads: #{Engine.rows_read/benchmarks[:after_reads]} rows/sec\" if benchmarks [ :after_reads ] > 0 say \"Avg before_writes: #{Engine.rows_read/benchmarks[:before_writes]} rows/sec\" if benchmarks [ :before_writes ] > 0 say \"Avg transforms: #{Engine.rows_read/benchmarks[:transforms]} rows/sec\" if benchmarks [ :transforms ] > 0 say \"Avg writes: #{Engine.rows_read/benchmarks[:writes]} rows/sec\" if benchmarks [ :writes ] > 0 # say \"Avg time writing execution records: #{ETL::Execution::Record.average_time_spent}\" #  # ETL::Transform::Transform.benchmarks.each do |klass, t| #         say \"Avg #{klass}: #{Engine.rows_read/t} rows/sec\" #       end ActiveRecord :: Base . verify_active_connections! ETL :: Engine . job . completed_at = Time . now ETL :: Engine . job . status = ( errors . length > 0 ? 'completed with errors' : 'completed' ) ETL :: Engine . job . save! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute all preprocessors [CODESPLIT] def pre_process ( control ) Engine . logger . debug \"Pre-processing #{control.file}\" control . pre_processors . each do | processor | processor . process end Engine . logger . debug \"Pre-processing complete\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute all postprocessors [CODESPLIT] def post_process ( control ) say_on_own_line \"Executing post processes\" Engine . logger . debug \"Post-processing #{control.file}\" control . post_processors . each do | processor | processor . process end Engine . logger . debug \"Post-processing complete\" say \"Post-processing complete\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute all dependencies [CODESPLIT] def execute_dependencies ( control ) Engine . logger . debug \"Executing dependencies\" control . dependencies . flatten . each do | dependency | case dependency when Symbol f = dependency . to_s + '.ctl' Engine . logger . debug \"Executing dependency: #{f}\" say \"Executing dependency: #{f}\" process ( f ) when String Engine . logger . debug \"Executing dependency: #{f}\" say \"Executing dependency: #{f}\" process ( dependency ) else raise \"Invalid dependency type: #{dependency.class}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute all screens [CODESPLIT] def execute_screens ( control , timing = :before_post_process ) screens = case timing when :after_post_process control . after_post_process_screens else # default to before post-process screens control . screens end [ :fatal , :error , :warn ] . each do | type | screens [ type ] . each do | block | begin block . call rescue => e case type when :fatal raise FatalScreenError , e when :error raise ScreenError , e when :warn say \"Screen warning: #{e}\" end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "add new field which will be saved into redis * name - name of your variable * type - type of your variable ( : integer : float : string : array : hash ) * ( default ) - default value of your variable [CODESPLIT] def redis_field name , type , default = nil redis_user_field_config << name # remember field to save into redis redis_fields_config [ name ] = type # remember field default value redis_fields_defaults_config [ name ] = default define_attribute_method name end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "set redis key which will be used for storing model [CODESPLIT] def redis_key * fields @redis_key_config = fields . flatten validate_redis_key #own specification of redis key - delete autoincrement remove_redis_autoincrement_key unless redis_user_field_config . include? ( :id ) || @redis_key_config . include? ( :id ) # automaticaly add all fields from key to validation # if any of fields in redis key is nil # then prevent to save it @redis_key_config . each do | field | validates field , :presence => :true if field != :id end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "set redis model to normalize redis keys [CODESPLIT] def redis_key_normalize * metrics @redis_key_normalize_conf ||= [ ] metrics . each do | metric | raise ArgumentError , \"Please provide valid normalization: #{VALID_NORMALIZATIONS.join(\", \")}\" unless VALID_NORMALIZATIONS . include? ( metric ) @redis_key_normalize_conf << metric end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "store informations about redis aliases [CODESPLIT] def redis_alias name , main_fields , name_of_field_for_order = nil , name_of_field_for_args = nil #set fields if they are not allready set! if name_of_field_for_order && name_of_field_for_args redis_field name_of_field_for_order , :array , [ ] unless redis_fields_config . has_key? ( name_of_field_for_order ) redis_field name_of_field_for_args , :hash , { } unless redis_fields_config . has_key? ( name_of_field_for_args ) end @redis_alias_config ||= { } #add specification of dynamic alias @redis_alias_config [ name ] = { main_fields : main_fields , order_field : name_of_field_for_order , args_field : name_of_field_for_args , } #create alias methods for find and get (find_by_name, get_by_name) create_class_alias_method ( name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "set old arguments [CODESPLIT] def store_redis_keys args = to_arg #store main key redis_old_keys [ :key ] = self . class . generate_key ( args ) #store main key #store alias keys redis_old_keys [ :aliases ] = [ ] redis_alias_config . each do | alias_name , fields | redis_old_keys [ :aliases ] << redis_alias_key ( alias_name ) if valid_alias_key? alias_name end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "old method to initialize redis model extenstion Usage : REDIS_MODEL_CONF = { : fields = > { : integer = > : to_i : boolean = > : to_bool : string = > : to_s : symbol = > : to_sym } : required = > [ : integer : string ] : redis_key = > [ : string : symbol ] : redis_aliases = > { : token = > [ : symbol ] } # ( default is true ) if true all nil values will not be saved into redis # there should be problem when you want to set some value to nil and same # it will not be saved ( use false to prevent this ) : reject_nil_values = > false } include RedisModel initialize_redis_model_methods REDIS_MODEL_CONF [CODESPLIT] def initialize_redis_model_methods conf puts \"WARNING: This initilization method is deprecated and will be removed in future! \\n Please read documentation how to change your model to use new initialization methods\" remove_redis_autoincrement_key @conf = { :reject_nil_values => true } . merge ( conf ) #take all fields and make methods for them conf [ :fields ] . each do | name , action | redis_fields_config [ name ] = TYPE_TRANSLATIONS . invert [ action ] redis_fields_defaults_config [ name ] = nil # define getter method for field define_method \"#{name}\" do value_get name end # define setter method for field define_method \"#{name}=\" do | new_value | value_set name , new_value end # define exists? method for field define_method \"#{name}?\" do value_get ( name ) && ! value_get ( name ) . blank? ? true : false end end # save nil values? redis_save_fields_with_nil false if ! conf . has_key? ( :reject_nil_values ) || conf [ :reject_nil_values ] == true # save into class config about redis key @redis_key_config = conf [ :redis_key ] #validate presence of all fields in key @required_config = ( @redis_key_config | conf [ :required ] ) ( @redis_key_config | conf [ :required ] ) . each do | field | validates field , :presence => :true end # save into class config about redis keys @redis_alias_config = { } conf [ :redis_aliases ] . each do | key , fields | @redis_alias_config [ key ] = { main_fields : fields , order_field : nil , args_field : nil , } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "get config hash [CODESPLIT] def conf fields = { } redis_fields_config . each do | key , type | fields [ key ] = TYPE_TRANSLATIONS [ type ] if TYPE_TRANSLATIONS . has_key? ( type ) end { fields : fields , required : @required_config . sort , redis_key : redis_key_config , redis_aliases : redis_alias_config . inject ( { } ) { | o , ( k , v ) | o [ k ] = v [ :main_fields ] ; o } , reject_nil_values : ! redis_save_fields_with_nil_conf , } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates redis key for storing object * will produce something like : your_class : key : field_value1 : field_value2 ... ( depending on your redis_key setting ) [CODESPLIT] def generate_key args = { } , key = \"key\" #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) out = \"#{self.name.to_s.underscore.to_sym}:#{key}\" redis_key_config . each do | key | out += add_item_to_redis_key args , key end out end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates redis key for storing indexes for dynamic aliases will produce something like : your_class : dynamic : name_of_your_dynami_alias : field_value2 : field_value1 ... ( field values are sorted by fields order ) * dynamic_alias_name ( Symbol ) - name of your dynamic alias * args ( Hash ) - arguments of your model * field_order ( Array of symbols ) - order of fields ( ex . [ : field2 : field1 ] ) * field_args ( Hash ) - hash of values for aliasing ( ex . { : field1 = > field_value1 : field2 = > field_value2 } ) [CODESPLIT] def generate_alias_key alias_name , args = { } #check if asked dynamic alias exists raise ArgumentError , \"Unknown dynamic alias: '#{alias_name}', use: #{redis_alias_config.keys.join(\", \")} \" unless redis_alias_config . has_key? ( alias_name . to_sym ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) # prepare class name + dynamic + alias name out = \"#{self.name.to_s.underscore.to_sym}:alias:#{alias_name}\" #get config  config = redis_alias_config [ alias_name . to_sym ] # use all specified keys config [ :main_fields ] . each do | key | out += add_item_to_redis_key args , key end #is alias dynamic? if config [ :order_field ] && config [ :args_field ] #check if input arguments has order field if args . has_key? ( config [ :order_field ] ) && args [ config [ :order_field ] ] && args . has_key? ( config [ :args_field ] ) && args [ config [ :args_field ] ] #use filed order from defined field in args args [ config [ :order_field ] ] . each do | key | out += add_item_to_redis_key args [ config [ :args_field ] ] , key end else # use global search out += \":*\" end end out end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if key by arguments exists in db [CODESPLIT] def exists? args = { } RedisModelExtension :: Database . redis . exists ( self . name . constantize . generate_key ( args ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if key by alias name and arguments exists in db [CODESPLIT] def alias_exists? alias_name , args = { } RedisModelExtension :: Database . redis . exists ( self . name . constantize . generate_alias_key ( alias_name , args ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return one item of redis key ( will decide to input value or to add * for search ) [CODESPLIT] def add_item_to_redis_key args , key if args . has_key? ( key ) && ! args [ key ] . nil? key = \":#{args[key]}\" key = key . mb_chars . downcase if redis_key_normalize_conf . include? ( :downcase ) key = ActiveSupport :: Inflector :: transliterate ( key ) if redis_key_normalize_conf . include? ( :transliterate ) key else \":*\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validates if key by arguments is valid ( all needed fields are not nil! ) [CODESPLIT] def valid_key? args = { } #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) redis_key_config . each do | key | return false unless valid_item_for_redis_key? args , key end return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validates if key by alias name and arguments is valid ( all needed fields are not nil! ) [CODESPLIT] def valid_alias_key? alias_name , args = { } raise ArgumentError , \"Unknown dynamic alias, use: #{redis_alias_config.keys.join(\", \")}\" unless redis_alias_config . has_key? ( alias_name . to_sym ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) config = redis_alias_config [ alias_name . to_sym ] # use all specified keys config [ :main_fields ] . each do | key | return false unless valid_item_for_redis_key? args , key end # is dynamic alias? if config [ :order_field ] && config [ :args_field ] #check if input arguments has order field if args . has_key? ( config [ :order_field ] ) && args [ config [ :order_field ] ] && args . has_key? ( config [ :args_field ] ) && args [ config [ :args_field ] ] #use filed order from defined field in args args [ config [ :order_field ] ] . each do | key | return false unless valid_item_for_redis_key? args [ config [ :args_field ] ] , key end else return false end end return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "validate one item of redis key [CODESPLIT] def valid_item_for_redis_key? args , key ( args . has_key? ( key ) && ! args [ key ] . nil? ) || redis_fields_config [ key ] == :autoincrement end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "look for bad cofiguration in redis key and raise argument error [CODESPLIT] def validate_redis_key valid_fields = redis_fields_config . select { | k , v | v != :array && v != :hash } . keys bad_fields = redis_key_config - valid_fields raise ArgumentError , \"Sorry, but you cannot use as redis key [nonexisting | array | hash] fields: [#{bad_fields.join(\",\")}], availible are: #{valid_fields.join(\", \")}\" unless bad_fields . size == 0 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "take all arguments and send them out [CODESPLIT] def to_arg redis_fields_config . inject ( { } ) do | args , ( key , type ) | args [ key ] = self . send ( key ) args end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "FIND METHODS [CODESPLIT] def find ( args = { } ) # when argument is integer - search by id args = { id : args } if args . is_a? ( Integer ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) out = [ ] klass = self . name . constantize search_key = klass . generate_key ( args ) #is key specified directly? -> no needs of looking for other keys! -> faster unless search_key =~ / \\* / out << klass . new_by_key ( search_key ) if klass . exists? ( args ) else RedisModelExtension :: Database . redis . keys ( search_key ) . each do | key | out << klass . new_by_key ( key ) end end out end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find method for searching in redis [CODESPLIT] def find_by_alias ( alias_name , args = { } ) #check if asked dynamic alias exists raise ArgumentError , \"Unknown dynamic alias: '#{alias_name}', use: #{redis_alias_config.keys.join(\", \")} \" unless redis_alias_config . has_key? ( alias_name . to_sym ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) out = [ ] klass = self . name . constantize search_key = klass . generate_alias_key ( alias_name , args ) #is key specified directly? -> no needs of looking for other keys! -> faster unless search_key =~ / \\* / out = klass . get_by_alias ( alias_name , args ) if klass . alias_exists? ( alias_name , args ) else RedisModelExtension :: Database . redis . keys ( search_key ) . each do | key | out << klass . get_by_alias_key ( key ) end end out . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET BY ARGUMENTS [CODESPLIT] def get ( args = { } ) # when argument is integer - search by id args = { id : args } if args . is_a? ( Integer ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) klass = self . name . constantize if klass . valid_key? ( args ) && klass . exists? ( args ) klass . new_by_key ( klass . generate_key ( args ) ) else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET BY REDIS KEYS [CODESPLIT] def get_by_alias ( alias_name , args = { } ) #check if asked dynamic alias exists raise ArgumentError , \"Unknown dynamic alias: '#{alias_name}', use: #{redis_alias_config.keys.join(\", \")} \" unless redis_alias_config . has_key? ( alias_name . to_sym ) #normalize input hash of arguments args = HashWithIndifferentAccess . new ( args ) klass = self . name . constantize if klass . valid_alias_key? ( alias_name , args ) && klass . alias_exists? ( alias_name , args ) out = [ ] RedisModelExtension :: Database . redis . smembers ( klass . generate_alias_key ( alias_name , args ) ) . each do | key | item = klass . new_by_key ( key ) out << item if item end return out end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET BY REDIS KEYS [CODESPLIT] def get_by_redis_key ( redis_key ) if redis_key . is_a? ( String ) klass = self . name . constantize klass . new_by_key ( redis_key ) else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fastest method to get object from redis by getting it by alias and arguments [CODESPLIT] def get_by_alias_key ( alias_key ) klass = self . name . constantize if RedisModelExtension :: Database . redis . exists ( alias_key ) out = [ ] RedisModelExtension :: Database . redis . smembers ( alias_key ) . each do | key | item = klass . new_by_key ( key ) out << item if item end return out end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "CREATE NEW OBJECT BY HASH VALUES [CODESPLIT] def new_by_key ( key ) args = RedisModelExtension :: Database . redis . hgetall ( key ) return nil unless args && args . any? args . symbolize_keys! new_instance = new ( args ) new_instance . store_keys return new_instance end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "choose right type of value and then transform it for redis [CODESPLIT] def value_to_redis name , value if redis_fields_config . has_key? ( name ) value_transform value , redis_fields_config [ name ] else value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "convert value for valid format which can be saved in redis [CODESPLIT] def value_transform value , type return nil if value . nil? || value . to_s . size == 0 case type when :integer then value . to_i when :autoincrement then value . to_i when :string then value . to_s when :float then value . to_f when :bool then value . to_s when :symbol then value . to_s when :marshal then Marshal . dump ( value ) when :array then Yajl :: Encoder . encode ( value ) when :hash then Yajl :: Encoder . encode ( value ) when :time then Time . parse ( value . to_s ) . strftime ( \"%Y.%m.%d %H:%M:%S\" ) when :date then Date . parse ( value . to_s ) . strftime ( \"%Y-%m-%d\" ) else value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "convert value from redis into valid format in ruby [CODESPLIT] def value_parse value , type return nil if value . nil? || value . to_s . size == 0 case type when :integer then value . to_i when :autoincrement then value . to_i when :string then value . to_s when :float then value . to_f when :bool then value . to_s . to_bool when :symbol then value . to_s . to_sym when :marshal then value . is_a? ( String ) ? Marshal . load ( value ) : value when :array then value . is_a? ( String ) ? Yajl :: Parser . parse ( value ) : value when :hash then value . is_a? ( String ) ? Hashr . new ( Yajl :: Parser . parse ( value ) ) : Hashr . new ( value ) when :time then value . is_a? ( String ) ? Time . parse ( value ) : value when :date then value . is_a? ( String ) ? Date . parse ( value ) : value else value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "save method - save all attributes ( fields ) and create aliases [CODESPLIT] def save perform = lambda do # can be saved into redis? if valid? #autoicrement id self . send ( \"id=\" , increment_id ) if redis_key_config . include? ( :id ) && ! self . id? #generate key (possibly new) generated_key = redis_key #take care about renaming saved hash in redis (if key changed) if redis_old_keys [ :key ] && redis_old_keys [ :key ] != generated_key && RedisModelExtension :: Database . redis . exists ( redis_old_keys [ :key ] ) RedisModelExtension :: Database . redis . rename ( redis_old_keys [ :key ] , generated_key ) end #ignore nil values for save  args = self . class . redis_save_fields_with_nil_conf ? to_arg : to_arg . reject { | k , v | v . nil? } #perform save to redis hash RedisModelExtension :: Database . redis . hmset ( generated_key , args . inject ( [ ] ) { | arr , kv | arr + [ kv [ 0 ] , value_to_redis ( kv [ 0 ] , kv [ 1 ] ) ] } ) # destroy aliases destroy_aliases! create_aliases #after save make sure instance remember old key to know if it needs to be ranamed store_keys end end run_callbacks :save do unless exists? run_callbacks :create do perform . ( ) end else perform . ( ) end end unless errors . any? return self else return false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create aliases ( create key value [ STRING ] key is alias redis key and value is redis key ) [CODESPLIT] def create_aliases main_key = redis_key redis_alias_config . each do | alias_name , fields | RedisModelExtension :: Database . redis . sadd ( redis_alias_key ( alias_name ) , main_key ) if valid_alias_key? alias_name end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "update multiple attrubutes at once [CODESPLIT] def update args args . each do | key , value | method = \"#{key}=\" . to_sym if self . respond_to? method self . send ( method , value ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "remove all aliases [CODESPLIT] def destroy_aliases! #do it only if it is existing object! if redis_old_keys [ :aliases ] . size > 0 redis_old_keys [ :aliases ] . each do | alias_key | RedisModelExtension :: Database . redis . srem alias_key , redis_old_keys [ :key ] #delete alias with 0 keys RedisModelExtension :: Database . redis . del ( alias_key ) if RedisModelExtension :: Database . redis . scard ( alias_key ) . to_i == 0 end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add entry to Apple Keychain [CODESPLIT] def add ( username , token ) Firim :: AccountManager . new ( user : username , token : token ) . add_to_keychain end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks the response code for common errors . Returns parsed response for successful requests . [CODESPLIT] def validate ( response ) error_klass = case response . code when 400 then Error :: BadRequest when 401 then Error :: Unauthorized when 403 then Error :: Forbidden when 404 then Error :: NotFound when 405 then Error :: MethodNotAllowed when 409 then Error :: Conflict when 422 then Error :: Unprocessable when 500 then Error :: InternalServerError when 502 then Error :: BadGateway when 503 then Error :: ServiceUnavailable end fail error_klass . new ( response ) if error_klass parsed = response . parsed_response parsed . client = self if parsed . respond_to? ( :client= ) parsed . parse_headers! ( response . headers ) if parsed . respond_to? ( :parse_headers! ) parsed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array of nsqd addresses If there s an error return nil [CODESPLIT] def get_nsqds ( lookupd , topic = nil ) uri_scheme = 'http://' unless lookupd . match ( %r( ) ) uri = URI . parse ( \"#{uri_scheme}#{lookupd}\" ) uri . query = \"ts=#{Time.now.to_i}\" if topic uri . path = '/lookup' uri . query += \"&topic=#{URI.escape(topic)}\" else uri . path = '/nodes' end begin body = Net :: HTTP . get ( uri ) data = JSON . parse ( body ) producers = data [ 'producers' ] || # v1.0.0-compat ( data [ 'data' ] && data [ 'data' ] [ 'producers' ] ) if producers producers . map do | producer | \"#{producer['broadcast_address']}:#{producer['tcp_port']}\" end else [ ] end rescue Exception => e error \"Error during discovery for #{lookupd}: #{e}\" nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "discovers nsqds from an nsqlookupd repeatedly [CODESPLIT] def discover_repeatedly ( opts = { } ) @discovery_thread = Thread . new do @discovery = Discovery . new ( opts [ :nsqlookupds ] ) loop do begin nsqds = nsqds_from_lookupd ( opts [ :topic ] ) drop_and_add_connections ( nsqds ) rescue DiscoveryException # We can't connect to any nsqlookupds. That's okay, we'll just # leave our current nsqd connections alone and try again later. warn 'Could not connect to any nsqlookupd instances in discovery loop' end sleep opts [ :interval ] end end @discovery_thread . abort_on_exception = true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retry the supplied block with exponential backoff . [CODESPLIT] def with_retries ( & block ) base_sleep_seconds = 0.5 max_sleep_seconds = 300 # 5 minutes # Let's do this thing attempts = 0 begin attempts += 1 return block . call ( attempts ) rescue Errno :: ECONNREFUSED , Errno :: ECONNRESET , Errno :: EHOSTUNREACH , Errno :: ENETDOWN , Errno :: ENETUNREACH , Errno :: ETIMEDOUT , Timeout :: Error => ex raise ex if attempts >= 100 # The sleep time is an exponentially-increasing function of base_sleep_seconds. # But, it never exceeds max_sleep_seconds. sleep_seconds = [ base_sleep_seconds * ( 2 ** ( attempts - 1 ) ) , max_sleep_seconds ] . min # Randomize to a random value in the range sleep_seconds/2 .. sleep_seconds sleep_seconds = sleep_seconds * ( 0.5 * ( 1 + rand ( ) ) ) # But never sleep less than base_sleep_seconds sleep_seconds = [ base_sleep_seconds , sleep_seconds ] . max warn \"Failed to connect: #{ex}. Retrying in #{sleep_seconds.round(1)} seconds.\" snooze ( sleep_seconds ) retry end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Hash ] args - all possible parameters - @option [ String ] controller_class_name - @option [ Class ] controller_class - @option [ String ] verb - @option [ String ] operation_name - @option [ String ] model_name - @option [ Class ] model_class - @option [ Hash ] options PostsController = > PostOperations :: Verb [CODESPLIT] def operation_class @operation_class ||= begin found_namespace = ensure_namespace! ( operation_namespace ) operation = namespaced_operation_name . split ( found_namespace . name ) . last qualified_name = found_namespace ? found_namespace . name + operation : namespaced_operation_name ensure_operation_class! ( qualified_name ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "In order of most specific to least specific : - { action } _ { model_name } _params - { action } _params - { model_key } _params - resource_params - params [CODESPLIT] def params_for_action return { } if action_name == 'destroy' key = _options [ :model_params_key ] # model_class should be a class klass = _options [ :model_class ] model_key = if key . present? key elsif klass klass . name . underscore else _lookup . model_name . underscore end params_lookups = [ # e.g.: create_post_params \"#{action_name}_#{model_key}_params\" , # generic for action \"#{action_name}_params\" , # e.g.: post_params \"#{model_key}_params\" , # most generic 'resource_params' ] lookup_params_for_action ( params_lookups ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse_int [CODESPLIT] def parse_attributes ( e ) throw Exception . new ( \"No name attribute found for : #{e.inspect}\" ) unless name = e . attributes [ \"name\" ] throw Exception . new ( \"Cannot parse attribute 'min' for: #{e.inspect}\" ) unless min = parse_int ( e . attributes [ \"min\" ] ) throw Exception . new ( \"Cannot parse attribute 'max' for: #{e.inspect}\" ) unless max = parse_int ( e . attributes [ \"max\" ] ) throw Exception . new ( \"Cannot parse attribute 'type' for: #{e.inspect}\" ) unless type = parse_type ( e . attributes [ \"type\" ] ) throw Exception . new ( \"Cannot parse attribute 'required' for: #{e.inspect}\" ) if ( required = parse_boolean ( e . attributes [ \"required\" ] ) ) . nil? validation = e . attributes [ \"validation\" ] min = 1 if required and min < 1 max = 999999 if max == 0 return name , min , max , type , required , validation end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse_attributes [CODESPLIT] def parse_field ( e ) name , min , max , type , required , validation = parse_attributes ( e ) # FIXME - for compatibility with d12 - constants are stored in attribute 'type' and are enclosed in\r # double quotes\r const_field = e . attributes [ \"const\" ] if ( const_field ) type = \"\\\"#{const_field}\\\"\" end Field . new ( name , type , required , min , max , validation ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse_field [CODESPLIT] def parse_table ( e ) name , min , max , type , required , validation = parse_attributes ( e ) content = e . find ( \"Entry\" ) . inject ( { } ) { | t , entry | t [ entry . attributes [ \"name\" ] ] = entry . attributes [ \"value\" ] t } Table . new ( name , content ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a tree - like representation of the element [CODESPLIT] def show ( ind = '' ) count = 0 self . to_a . each { | i | #puts \"#{ind}#{i.name} #{i.object_id} #{i.super.object_id} [#{count}]: #{i.parsed_str} #{i.super.class}\"\r puts \"#{ind}#{i.name} [#{count}]: #{i.to_s.sub(/^(.{30})(.*?)(.{30})$/, '\\1...\\3')}\" # Force parsing a segment\r if i . kind_of? ( X12 :: Segment ) && i . nodes [ 0 ] i . find_field ( i . nodes [ 0 ] . name ) end i . nodes . each { | j | case when j . kind_of? ( X12 :: Base ) then j . show ( ind + '  ' ) when j . kind_of? ( X12 :: Field ) then puts \"#{ind+'  '}#{j.name} -> '#{j.to_s}'\" end } count += 1 } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Try to parse the current element one more time if required . Returns the rest of the string or the same string if no more repeats are found or required . [CODESPLIT] def do_repeats ( s ) if self . repeats . end > 1 possible_repeat = self . dup p_s = possible_repeat . parse ( s ) if p_s s = p_s self . next_repeat = possible_repeat end # if parsed\r end # more repeats\r s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make a deep copy of the element dup Recursively find a sub - element which also has to be of type Base . [CODESPLIT] def find ( e ) #puts \"Finding [#{e}] in #{self.class} #{name}\"\r case self when X12 :: Loop # Breadth first\r res = nodes . find { | i | e == i . name } return res if res # Depth now\r nodes . each { | i | res = i . find ( e ) if i . kind_of? ( X12 :: Loop ) return res unless res . nil? or EMPTY == res # otherwise keep looping\r } when X12 :: Segment return find_field ( e ) . to_s end # case\r return EMPTY end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Present self and all repeats as an array with self being #0 [CODESPLIT] def to_a res = [ self ] nr = self . next_repeat while nr do res << nr nr = nr . next_repeat end res end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The main method implementing Ruby - like access methods for nested elements [CODESPLIT] def method_missing ( meth , * args , & block ) str = meth . id2name str = str [ 1 .. str . length ] if str =~ / \\d / # to avoid pure number names like 270, 997, etc.\r #puts \"Missing #{str}\"\r if str =~ / / # Assignment\r str . chop! #puts str\r case self when X12 :: Segment res = find_field ( str ) throw Exception . new ( \"No field '#{str}' in segment '#{self.name}'\" ) if EMPTY == res res . content = args [ 0 ] . to_s #puts res.inspect\r else throw Exception . new ( \"Illegal assignment to #{meth} of #{self.class}\" ) end # case\r else # Retrieval\r res = find ( str ) yield res if block_given? res end # if assignment\r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a repeat to a segment or loop . Returns a new segment / loop or self if empty . [CODESPLIT] def repeat res = if self . has_content? # Do not repeat an empty segment\r last_repeat = self . to_a [ - 1 ] last_repeat . next_repeat = last_repeat . dup else self end yield res if block_given? res end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parses this segment out of a string puts the match into value returns the rest of the string - nil if cannot parse [CODESPLIT] def parse ( str ) s = str #puts \"Parsing segment #{name} from #{s} with regexp [#{regexp.source}]\"\r m = regexp . match ( s ) #puts \"Matched #{m ? m[0] : 'nothing'}\"\r return nil unless m s = m . post_match self . parsed_str = m [ 0 ] s = do_repeats ( s ) #puts \"Parsed segment \"+self.inspect\r return s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse Render all components of this segment as string suitable for EDI [CODESPLIT] def render self . to_a . inject ( '' ) { | repeat_str , i | if i . repeats . begin < 1 and ! i . has_content? # Skip optional empty segments\r repeat_str else # Have to render no matter how empty\r repeat_str += i . name + i . nodes . reverse . inject ( '' ) { | nodes_str , j | field = j . render ( j . required or nodes_str != '' or field != '' ) ? field_separator + field + nodes_str : nodes_str } + segment_separator end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "render Returns a regexp that matches this particular segment [CODESPLIT] def regexp unless @regexp if self . nodes . find { | i | i . type =~ / / } # It's a very special regexp if there are constant fields\r re_str = self . nodes . inject ( \"^#{name}#{Regexp.escape(field_separator)}\" ) { | s , i | field_re = i . simple_regexp ( field_separator , segment_separator ) + Regexp . escape ( field_separator ) + '?' field_re = \"(#{field_re})?\" unless i . required s + field_re } + Regexp . escape ( segment_separator ) @regexp = Regexp . new ( re_str ) else # Simple match\r @regexp = Regexp . new ( \"^#{name}#{Regexp.escape(field_separator)}[^#{Regexp.escape(segment_separator)}]*#{Regexp.escape(segment_separator)}\" ) end #puts sprintf(\"%s %p\", name, @regexp)\r end @regexp end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds a field in the segment . Returns EMPTY if not found . [CODESPLIT] def find_field ( str ) #puts \"Finding field [#{str}] in #{self.class} #{name}\"\r # If there is such a field to begin with\r field_num = nil self . nodes . each_index { | i | field_num = i if str == self . nodes [ i ] . name } return EMPTY if field_num . nil? #puts field_num\r # Parse the segment if not parsed already\r unless @fields @fields = self . to_s . chop . split ( Regexp . new ( Regexp . escape ( field_separator ) ) ) self . nodes . each_index { | i | self . nodes [ i ] . content = @fields [ i + 1 ] } end #puts self.nodes[field_num].inspect\r return self . nodes [ field_num ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a parser out of a definition initialize Parse a loop of a given name out of a string . Throws an exception if the loop name is not defined . [CODESPLIT] def parse ( loop_name , str ) loop = @x12_definition [ X12 :: Loop ] [ loop_name ] #puts \"Loops to parse #{@x12_definition[X12::Loop].keys}\"\r throw Exception . new ( \"Cannot find a definition for loop #{loop_name}\" ) unless loop loop = loop . dup loop . parse ( str ) return loop end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse Make an empty loop to be filled out with information [CODESPLIT] def factory ( loop_name ) loop = @x12_definition [ X12 :: Loop ] [ loop_name ] throw Exception . new ( \"Cannot find a definition for loop #{loop_name}\" ) unless loop loop = loop . dup return loop end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Recursively scan the loop and instantiate fields definitions for all its segments [CODESPLIT] def process_loop ( loop ) loop . nodes . each { | i | case i when X12 :: Loop then process_loop ( i ) when X12 :: Segment then process_segment ( i ) unless i . nodes . size > 0 else return end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Instantiate segment s fields as previously defined [CODESPLIT] def process_segment ( segment ) #puts \"Trying to process segment #{segment.inspect}\"\r unless @x12_definition [ X12 :: Segment ] && @x12_definition [ X12 :: Segment ] [ segment . name ] # Try to find it in a separate file if missing from the @x12_definition structure\r initialize ( segment . name + '.xml' ) segment_definition = @x12_definition [ X12 :: Segment ] [ segment . name ] throw Exception . new ( \"Cannot find a definition for segment #{segment.name}\" ) unless segment_definition else segment_definition = @x12_definition [ X12 :: Segment ] [ segment . name ] end segment_definition . nodes . each_index { | i | segment . nodes [ i ] = segment_definition . nodes [ i ] # Make sure we have the validation table if any for this field. Try to read one in if missing.\r table = segment . nodes [ i ] . validation if table unless @x12_definition [ X12 :: Table ] && @x12_definition [ X12 :: Table ] [ table ] initialize ( table + '.xml' ) throw Exception . new ( \"Cannot find a definition for table #{table}\" ) unless @x12_definition [ X12 :: Table ] && @x12_definition [ X12 :: Table ] [ table ] end end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def regexp [CODESPLIT] def parse ( str ) #puts \"Parsing loop #{name}: \"+str\r s = str nodes . each { | i | m = i . parse ( s ) s = m if m } if str == s return nil else self . parsed_str = str [ 0 .. - s . length - 1 ] s = do_repeats ( s ) end #puts 'Parsed loop '+self.inspect\r return s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parse Render all components of this loop as string suitable for EDI [CODESPLIT] def render if self . has_content? self . to_a . inject ( '' ) { | loop_str , i | loop_str += i . nodes . inject ( '' ) { | nodes_str , j | nodes_str += j . render } } else '' end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert a hash ( and it s values recursively ) to NodeBlueprints . This is a helper method allowing a hash to be passed in to Node#properties = when only properties need to be set . One caveat : all node types will default to nt : unstructured . [CODESPLIT] def convert_hash_to_node_blueprint ( hash ) hash . keys . each do | key | if hash [ key ] . is_a? Hash hash [ key ] = convert_hash_to_node_blueprint ( hash [ key ] ) end end NodeBlueprint . new ( :path => :no_path , :properties => hash ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "format : [ dollars ] [ cents ] only one is required and it must consist only of numbers [CODESPLIT] def validate_response ( value ) if value . select { | k , v | k . in? ( [ 'dollars' , 'cents' ] ) && v . present? } . find { | k , v | ( Float ( v ) rescue nil ) . nil? } . present? \"isn't a valid price.\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "for manual use maybe when migrating [CODESPLIT] def calculate_sortable_values response_fieldable . input_fields . each do | response_field | if ( x = response_value ( response_field ) ) . present? get_responses [ \"#{response_field.id}_sortable_value\" ] = response_field . sortable_value ( x ) end end mark_responses_as_changed! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Normalizations get run before validation . [CODESPLIT] def normalize_responses return if form . blank? form . response_fields . each do | response_field | if ( x = self . response_value ( response_field ) ) response_field . normalize_response ( x , get_responses ) end end mark_responses_as_changed! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Audits get run explicitly . [CODESPLIT] def audit_responses form . response_fields . each do | response_field | response_field . audit_response ( self . response_value ( response_field ) , get_responses ) end mark_responses_as_changed! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Construct a new builder and start building [CODESPLIT] def tag! ( tag , * args , & block ) text , attributes = nil , { } args . each do | arg | case arg when :: Hash attributes . merge! ( arg ) when :: String text ||= '' text << arg end end @stack << [ tag , attributes , text ? [ text ] : [ ] ] if block _process ( block ) end if @stack . length > 1 node = @stack . pop @stack . last [ 2 ] << node NodeBuilder . new ( node , self ) else NodeBuilder . new ( @stack . last , self ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Hexp objects to the current tag [CODESPLIT] def << ( * args ) args . each do | arg | if arg . respond_to? ( :to_hexp ) @stack . last [ 2 ] << arg self else :: Kernel . raise :: Hexp :: FormatError , \"Inserting literal HTML into a builder with << is deliberately not supported by Hexp\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replace nodes in a tree [CODESPLIT] def rewrite ( css_selector = nil , & block ) return Rewriter . new ( self , block ) if css_selector . nil? CssSelection . new ( self , css_selector ) . rewrite ( block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Select nodes based on a css selector [CODESPLIT] def select ( css_selector = nil , & block ) if css_selector CssSelection . new ( self , css_selector ) . each ( block ) else Selection . new ( self , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set an attribute used internally by #attr [CODESPLIT] def set_attr ( name , value ) if value . nil? new_attrs = { } attributes . each do | nam , val | new_attrs [ nam ] = val unless nam == name . to_s end else new_attrs = attributes . merge ( name . to_s => value . to_s ) end self . class . new ( self . tag , new_attrs , self . children ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "* Safely * evaluate a conditional expression [CODESPLIT] def evaluate ( expression , user , resource ) Array ( expression ) . flat_map do | el | if expression? ( el ) cache . fetch ( el ) { type , * ary = el . split ( '::' ) if type == 'user' Array ( ary . inject ( user ) do | rval , attr | rval . freeze . public_send ( attr ) end ) elsif type == 'resource' Array ( ary . inject ( resource ) do | rval , attr | rval . freeze . public_send ( attr ) end ) else raise \"Expected #{type} to be 'resource' or 'user'\" end } else el end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extend configuration variables [CODESPLIT] def add_configuration ( config_hash ) config_hash . each do | key , val | instance_eval { instance_variable_set ( \"@#{key}\" , val ) } self . class . instance_eval { attr_accessor key } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check whether pid exists in the current process table . [CODESPLIT] def pid_exists ( pid ) return false if pid < 0 # According to \"man 2 kill\" PID 0 has a special meaning: # it refers to <<every process in the process group of the # calling process>> so we don't want to go any further. # If we get here it means this UNIX platform *does* have # a process with id 0. return true if pid == 0 :: Process . kill ( 0 , pid ) return true rescue Errno :: ESRCH # No such process return false rescue Errno :: EPERM # EPERM clearly means there's a process to deny access to return true rescue RangeError # the given pid is invalid. return false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wait for process with pid pid to terminate and return its exit status code as an integer . [CODESPLIT] def wait_pid ( pid , timeout = nil ) def check_timeout ( delay , stop_at , timeout ) if timeout raise Timeout :: Error . new ( \"when waiting for (pid=#{pid})\" ) if Time . now >= stop_at end sleep ( delay ) delay * 2 < 0.04 ? delay * 2 : 0.04 end if timeout waitcall = proc { :: Process . wait ( pid , :: Process :: WNOHANG ) } stop_at = Time . now + timeout else waitcall = proc { :: Process . wait ( pid ) } end delay = 0.0001 loop do begin retpid = waitcall . call ( ) rescue Errno :: EINTR delay = check_timeout ( delay , stop_at , timeout ) next rescue Errno :: ECHILD # This has two meanings: # - pid is not a child of Process.pid in which case #   we keep polling until it's gone # - pid never existed in the first place # In both cases we'll eventually return nil as we # can't determine its exit status code. loop do return nil unless pid_exists ( pid ) delay = check_timeout ( delay , stop_at , timeout ) end end unless retpid # WNOHANG was used, pid is still running delay = check_timeout ( delay , stop_at , timeout ) next end # process exited due to a signal; return the integer of # that signal if $? . signaled? return $? . termsig # process exited using exit(2) system call; return the # integer exit(2) system call has been called with elsif $? . exited? return $? . exitstatus else # should never happen raise RuntimeError . new ( \"unknown process exit status\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "upload the content of the module [CODESPLIT] def upload_module_changes ( parent_sha1 , sha1s ) remote_path = fetch_module # search for the first revision that is not  tmp_git_path = clone_or_fetch_repository ( remote_path , module_tmp_git_path ( @remote_path ) ) RIM :: git_session ( tmp_git_path ) do | dest | local_branch = nil remote_branch = nil infos = nil if @module_info . subdir dest_path = File . join ( [ tmp_git_path ] + @module_info . subdir . split ( \"/\" ) ) else dest_path = tmp_git_path end RIM :: git_session ( @ws_root ) do | src | infos = get_branches_and_revision_infos ( src , dest , parent_sha1 , sha1s ) if infos . branches . size == 1 remote_branch = infos . branches [ 0 ] if dest . has_remote_branch? ( remote_branch ) infos . rev_infos . each do | rev_info | local_branch = create_update_branch ( dest , infos . parent_sha1 , rev_info . src_sha1 ) if ! local_branch copy_revision_files ( src , rev_info . src_sha1 , dest_path , rev_info . rim_info . ignores ) commit_changes ( dest , local_branch , rev_info . src_sha1 , rev_info . message ) end else raise RimException . new ( \"The target revision '#{@module_info.target_revision}' of module #{@module_info.local_path} is not a branch. No push can be performed.\" ) end elsif infos . branches . size > 1 raise RimException . new ( \"There are commits for module #{@module_info.local_path} on multiple target revisions (#{infos.branches.join(\", \")}).\" ) end end # Finally we're done. Push the changes if local_branch && dest . rev_sha1 ( local_branch ) != infos . parent_sha1 push_branch = @review && @module_info . remote_branch_format && ! @module_info . remote_branch_format . empty? ? @module_info . remote_branch_format % remote_branch : remote_branch dest . execute ( \"git push #{@remote_url} #{local_branch}:#{push_branch}\" ) dest . execute ( \"git checkout --detach #{local_branch}\" ) dest . execute ( \"git branch -D #{local_branch}\" ) @logger . info ( \"Commited changes for module #{@module_info.local_path} to remote branch #{push_branch}.\" ) else @logger . info ( \"No changes to module #{@module_info.local_path}.\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "search backwards for all revision infos [CODESPLIT] def get_branches_and_revision_infos ( src_session , dest_session , parent_sha1 , sha1s ) infos = [ ] branches = [ ] dest_parent_sha1 = nil ( sha1s . size ( ) - 1 ) . step ( 0 , - 1 ) do | i | info = get_revision_info ( src_session , dest_session , sha1s [ i ] ) if ! info . dest_sha1 && info . rim_info . target_revision infos . unshift ( info ) branches . push ( info . rim_info . target_revision ) if ! branches . include? ( info . rim_info . target_revision ) else dest_parent_sha1 = info . dest_sha1 break end end dest_parent_sha1 = get_riminfo_for_revision ( src_session , parent_sha1 ) . revision_sha1 if ! dest_parent_sha1 dest_parent_sha1 = infos . first . rim_info . revision_sha1 if ! dest_parent_sha1 && ! infos . empty? return Struct . new ( :branches , :parent_sha1 , :rev_infos ) . new ( branches , dest_parent_sha1 , infos ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "collect infos for a revision [CODESPLIT] def get_revision_info ( src_session , dest_session , src_sha1 ) module_status = StatusBuilder . new . rev_module_status ( src_session , src_sha1 , @module_info . local_path ) rim_info = get_riminfo_for_revision ( src_session , src_sha1 ) dest_sha1 = dest_session . rev_sha1 ( \"rim-#{src_sha1}\" ) msg = src_session . execute ( \"git show -s --format=%B #{src_sha1}\" ) RevisionInfo . new ( module_status && module_status . dirty? ? dest_sha1 : rim_info . revision_sha1 , src_sha1 , rim_info , msg ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "commit changes to session [CODESPLIT] def commit_changes ( session , branch , sha1 , msg ) if session . status . lines . any? # add before commit because the path can be below a not yet added path session . execute ( \"git add --all\" ) msg_file = Tempfile . new ( 'message' ) begin msg_file << msg msg_file . close session . execute ( \"git commit -F #{msg_file.path}\" ) ensure msg_file . close ( true ) end # create tag session . execute ( \"git tag rim-#{sha1} refs/heads/#{branch}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "get target revision for this module for workspace revision [CODESPLIT] def get_riminfo_for_revision ( session , sha1 ) session . execute ( \"git show #{sha1}:#{File.join(@module_info.local_path, RimInfo::InfoFileName)}\" ) do | out , e | return RimInfo . from_s ( ! e ? out : \"\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "copy files from given source revision into destination dir [CODESPLIT] def copy_revision_files ( src_session , src_sha1 , dest_dir , ignores ) Dir . mktmpdir do | tmp_dir | tmp_dir = Dir . glob ( tmp_dir ) [ 0 ] src_session . execute ( \"git archive --format tar #{src_sha1} #{@module_info.local_path} | tar -C #{tmp_dir} -xf -\" ) tmp_module_dir = File . join ( tmp_dir , @module_info . local_path ) files = FileHelper . find_matching_files ( tmp_module_dir , false , \"/**/*\" , File :: FNM_DOTMATCH ) files . delete ( \".\" ) files . delete ( \"..\" ) files . delete ( RimInfo :: InfoFileName ) files -= FileHelper . find_matching_files ( tmp_module_dir , false , ignores ) # have source files now. Now clear destination folder and copy prepare_empty_folder ( dest_dir , \".git/**/*\" ) files . each do | f | src_path = File . join ( tmp_module_dir , f ) if File . file? ( src_path ) path = File . join ( dest_dir , f ) FileUtils . mkdir_p ( File . dirname ( path ) ) FileUtils . cp ( src_path , path ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "status object tree for revision rev returns the root status object which points to any parent status objects note that merge commits mean that the status tree branches at the point were the merged branch branched off the status tree joins i . e . the parent status objects are the same at this point [CODESPLIT] def rev_history_status ( git_session , rev , options = { } ) stop_rev = options [ :stop_rev ] relevant_revs = { } if stop_rev git_session . execute ( \"git rev-list #{rev} \\\"^#{stop_rev}\\\"\" ) . split ( \"\\n\" ) . each do | r | relevant_revs [ r ] = true end elsif options [ :gerrit ] # in gerrit mode, stop on all known commits\r git_session . execute ( \"git rev-list #{rev} --not --all --\" ) . split ( \"\\n\" ) . each do | r | relevant_revs [ r ] = true end else # remote revs are where we stop traversal\r git_session . all_reachable_non_remote_revs ( rev ) . each do | r | relevant_revs [ r ] = true end end # make sure we deal only with sha1s\r rev = git_session . rev_sha1 ( rev ) build_rev_history_status ( git_session , rev , relevant_revs , { } , :fast => options [ :fast ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "status object for single revision + rev + without status of ancestors [CODESPLIT] def rev_status ( git_session , rev ) mod_dirs = module_dirs ( git_session , rev ) mod_stats = [ ] # export all relevant modules at once\r # this makes status calculation significantly faster compared\r # to exporting each module separately \r # (e.g. 1.0s instead of 1.5s on linux for a commit with 20 modules)\r git_session . within_exported_rev ( rev , mod_dirs ) do | d | mod_dirs . each do | rel_path | mod_stats << build_module_status ( d , d + \"/\" + rel_path ) end end stat = RevStatus . new ( mod_stats ) stat . git_rev = git_session . rev_sha1 ( rev ) stat end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "status object for a single module at + local_path + in revision + rev + returns nil if there is no such module in this revision [CODESPLIT] def rev_module_status ( git_session , rev , local_path ) mod_stat = nil if git_session . execute ( \"git ls-tree -r --name-only #{rev}\" ) . split ( \"\\n\" ) . include? ( File . join ( local_path , \".riminfo\" ) ) git_session . within_exported_rev ( rev , [ local_path ] ) do | d | mod_stat = build_module_status ( d , File . join ( d , local_path ) ) end end mod_stat end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "status object for the current file system content of dir this can by any directory even outside of any git working copy [CODESPLIT] def fs_status ( dir ) RevStatus . new ( fs_rim_dirs ( dir ) . collect { | d | build_module_status ( dir , d ) } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "building of the status of an ancestor chain works by checking the dirty state of modules only when any files affecting some module were changed ; otherwise the status of the module in the ancestor is assumed [CODESPLIT] def build_rev_history_status ( gs , rev , relevant_revs , status_cache = { } , options = { } ) return status_cache [ rev ] if status_cache [ rev ] stat = nil if relevant_revs [ rev ] parent_revs = gs . parent_revs ( rev ) if parent_revs . size > 0 # build status for all parent nodes\r parent_stats = parent_revs . collect do | p | build_rev_history_status ( gs , p , relevant_revs , status_cache , options ) end # if this is a merge commit with multiple parents\r # we decide to use the first commit (git primary parent)\r # note that it's not really important, which one we choose\r # just make sure to use the same commit when checking for changed files\r base_stat = parent_stats . first changed_files = gs . changed_files ( rev , parent_revs . first ) # build list of modules in this commit\r module_dirs = base_stat . modules . collect { | m | m . dir } changed_files . each do | f | if File . basename ( f . path ) == RimInfo :: InfoFileName if f . kind == :added module_dirs << File . dirname ( f . path ) elsif f . kind == :deleted module_dirs . delete ( File . dirname ( f . path ) ) end end end # a module needs to be checked if any of the files within were touched\r check_dirs = module_dirs . select { | d | changed_files . any? { | f | f . path . start_with? ( d ) } } module_stats = [ ] # check out all modules to be checked at once\r if check_dirs . size > 0 gs . within_exported_rev ( rev , check_dirs ) do | ws | check_dirs . each do | d | module_stats << build_module_status ( ws , File . join ( ws , d ) ) end end end ( module_dirs - check_dirs ) . each do | d | base_mod = base_stat . modules . find { | m | m . dir == d } module_stats << RevStatus :: ModuleStatus . new ( d , base_mod . rim_info , base_mod . dirty? ) end stat = RevStatus . new ( module_stats ) stat . git_rev = gs . rev_sha1 ( rev ) stat . parents . concat ( parent_stats ) else # no parents, need to do a full check\r if options [ :fast ] stat = rev_status_fast ( gs , rev ) else stat = rev_status ( gs , rev ) end end else # first \"non-relevant\", do the full check\r if options [ :fast ] stat = rev_status_fast ( gs , rev ) else stat = rev_status ( gs , rev ) end end status_cache [ rev ] = stat end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "creates a RevStatus object for + rev + with all modules assumend to be clean [CODESPLIT] def rev_status_fast ( git_session , rev ) mod_dirs = module_dirs ( git_session , rev ) mod_stats = [ ] git_session . within_exported_rev ( rev , mod_dirs . collect { | d | \"#{d}/#{RimInfo::InfoFileName}\" } ) do | temp_dir | mod_dirs . each do | rel_path | mod_stats << RevStatus :: ModuleStatus . new ( rel_path , RimInfo . from_dir ( \"#{temp_dir}/#{rel_path}\" ) , # never dirty\r false ) end end stat = RevStatus . new ( mod_stats ) stat . git_rev = git_session . rev_sha1 ( rev ) stat end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "export + revision + of + mod + into working copy BEWARE : any changes to the working copy target dir will be lost! [CODESPLIT] def export_module ( message ) changes = false RIM :: git_session ( @dest_root ) do | d | start_sha1 = d . rev_sha1 ( \"HEAD\" ) git_path = module_git_path ( @remote_path ) RIM :: git_session ( git_path ) do | s | if ! s . rev_sha1 ( @module_info . target_revision ) raise RimException . new ( \"Unknown target revision '#{@module_info.target_revision}' for module '#{@module_info.local_path}'.\" ) end local_path = File . join ( @dest_root , @module_info . local_path ) prepare_empty_folder ( local_path , @module_info . ignores ) temp_commit ( d , \"clear directory\" ) if d . uncommited_changes? strip = \"\" if @module_info . subdir depth = Pathname ( @module_info . subdir ) . each_filename . count ( ) strip = \"--strip-components=#{depth}\" end s . execute ( \"git archive --format tar #{@module_info.target_revision} #{@module_info.subdir} | tar #{strip} -C #{local_path} -xf -\" ) sha1 = s . execute ( \"git rev-parse #{@module_info.target_revision}\" ) . strip @rim_info = RimInfo . new @rim_info . remote_url = @module_info . remote_url @rim_info . target_revision = @module_info . target_revision @rim_info . revision_sha1 = sha1 @rim_info . ignores = @module_info . ignores . join ( \",\" ) @rim_info . subdir = @module_info . subdir @rim_info . infos = s . rev_infos ( @module_info . target_revision , RimInfo . git_infos ) @rim_info . to_dir ( local_path ) DirtyCheck . mark_clean ( local_path ) end temp_commit ( d , \"commit changes\" ) if needs_commit? ( d ) d . execute ( \"git reset --soft #{start_sha1}\" ) changes = d . uncommited_changes? commit ( d , message || \"rim sync: module #{@module_info.local_path}\" ) if changes end changes end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "sync all module changes into rim branch [CODESPLIT] def sync ( message = nil , rebase = nil , split = true ) # get the name of the current workspace branch RIM :: git_session ( @ws_root ) do | s | branch = s . current_branch || '' rim_branch = \"rim/\" + branch branch_sha1 = nil changed_modules = nil if branch . empty? raise RimException . new ( \"Not on a git branch.\" ) elsif branch . start_with? ( \"rim/\" ) raise RimException . new ( \"The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.\" ) else branch = \"refs/heads/#{branch}\" branch_sha1 = s . rev_sha1 ( rim_branch ) remote_rev = get_latest_remote_revision ( s , branch ) rev = get_latest_clean_path_revision ( s , branch , remote_rev ) if ! s . has_branch? ( rim_branch ) || has_ancestor? ( s , branch , s . rev_sha1 ( rim_branch ) ) || ! has_ancestor? ( s , rim_branch , remote_rev ) s . execute ( \"git branch -f #{rim_branch} #{rev}\" ) branch_sha1 = s . rev_sha1 ( rim_branch ) end remote_url = \"file://\" + @ws_root @logger . debug ( \"Folder for temporary git repositories: #{@rim_path}\" ) tmpdir = clone_or_fetch_repository ( remote_url , module_tmp_git_path ( \".ws\" ) , \"Cloning workspace git...\" ) RIM :: git_session ( tmpdir ) do | tmp_session | tmp_session . execute ( \"git reset --hard\" ) tmp_session . execute ( \"git clean -xdf\" ) # use -f here to prevent git checkout from checking for untracked files which might be overwritten.  # this is safe since we removed any untracked files before. # this is a workaround for a name case problem on windows: # if a file's name changes case between the current head and the checkout target, # git checkout will report the file with the new name as untracked and will fail tmp_session . execute ( \"git checkout -B #{rim_branch} -f remotes/origin/#{rim_branch}\" ) changed_modules = sync_modules ( tmp_session , message ) if ! split tmp_session . execute ( \"git reset --soft #{branch_sha1}\" ) commit ( tmp_session , message ? message : get_commit_message ( changed_modules ) ) if tmp_session . uncommited_changes? end tmp_session . execute ( \"git push #{remote_url} #{rim_branch}:#{rim_branch}\" ) end end if ! changed_modules . empty? if rebase s . execute ( \"git rebase #{rim_branch}\" ) @logger . info ( \"Changes have been commited to branch #{rim_branch} and workspace has been rebased successfully.\" ) else @logger . info ( \"Changes have been commited to branch #{rim_branch}. Rebase to apply changes to workspace.\" ) end else @logger . info ( \"No changes.\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "sync all modules [CODESPLIT] def sync_modules ( session , message ) module_helpers = [ ] @module_infos . each do | module_info | module_helpers . push ( SyncModuleHelper . new ( session . execute_dir , @ws_root , module_info , @logger ) ) end changed_modules = [ ] module_helpers . each do | m | @logger . info ( \"Synchronizing #{m.module_info.local_path}...\" ) if m . sync ( message ) changed_modules << m . module_info end end changed_modules end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "check whether revision has a given ancestor [CODESPLIT] def has_ancestor? ( session , rev , ancestor ) # make sure we deal only with sha1s rev = session . rev_sha1 ( rev ) return rev == ancestor || session . is_ancestor? ( ancestor , rev ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "get first parent node [CODESPLIT] def get_parent ( session , rev ) parents = session . parent_revs ( rev ) ! parents . empty? ? parents . first : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create default commit message from array of changed modules [CODESPLIT] def get_commit_message ( changed_modules ) StringIO . open do | s | s . puts \"rim sync.\" s . puts changed_modules . each do | m | s . puts m . local_path end s . string end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "============================================================ | FIELD | DESCRIPTION | AKA | TOP | ============================================================ | rss | resident set size | | RES | | vms | total program size | size | VIRT | | shared | shared pages ( from shared mappings ) | | SHR | | text | text ( code ) | trs | CODE | | lib | library ( unused in Linux 2 . 6 ) | lrs | | | data | data + stack | drs | DATA | | dirty | dirty pages ( unused in Linux 2 . 6 ) | dt | | ============================================================ [CODESPLIT] def memory_info_ex info = File . new ( \"/proc/#{@pid}/statm\" ) . readline . split [ 0 ... 7 ] vms , rss , shared , text , lib , data , dirty = info . map { | i | i . to_i * PAGE_SIZE } OpenStruct . new ( vms : vms , rss : rss , shared : shared , text : text , lib : lib , data : data , dirty : dirty ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "data in pmmap_ext is an Array [CODESPLIT] def pmmap_ext ( data ) pmmap_ext = [ 'addr' , 'perms' , 'path' , 'rss' , 'size' , 'pss' , 'shared_clean' , 'shared_dirty' , 'private_clean' , 'private_dirty' , 'referenced' , 'anonymous' , 'swap' ] os_list = [ ] data . each do | datum | os = OpenStruct . new pmmap_ext . each_index { | i | os [ pmmap_ext [ i ] ] = datum [ i ] } os_list . push ( os ) end os_list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "data in pmmap_grouped is a Hash [CODESPLIT] def pmmap_grouped ( data ) pmmap_grouped = [ 'rss' , 'size' , 'pss' , 'shared_clean' , 'shared_dirty' , 'private_clean' , 'private_dirty' , 'referenced' , 'anonymous' , 'swap' ] os_list = [ ] data . each do | k , v | os = OpenStruct . new os . path = k pmmap_grouped . each_index { | i | os [ pmmap_grouped [ i ] ] = v [ i ] } os_list . push ( os ) end os_list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns nil if checksum can t be calculated due to missing info [CODESPLIT] def calc_checksum ( mi , dir ) if check_required_attributes ( mi ) sha1 = Digest :: SHA1 . new # all files and directories within dir\r files = FileHelper . find_matching_files ( dir , false , \"/**/*\" , File :: FNM_DOTMATCH ) # Dir.glob with FNM_DOTMATCH might return . and ..\r files . delete ( \".\" ) files . delete ( \"..\" ) # ignore the info file itself\r files . delete ( RimInfo :: InfoFileName ) # ignores defined by user\r files -= FileHelper . find_matching_files ( dir , false , mi . ignores ) # order of files makes a difference\r # sort to eliminate platform specific glob behavior\r files . sort! files . each do | fn | update_file ( sha1 , dir , fn ) end ChecksumAttributes . each do | a | sha1 . update ( mi . send ( a ) ) end sha1 . hexdigest else # can't calc checksum\r nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns the current branch [CODESPLIT] def current_branch out = execute \"git branch\" out . split ( \"\\n\" ) . each do | l | if ! l . include? ( '(' ) && ( l =~ / \\* \\s \\S / ) return $1 end end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "check whether remote branch exists [CODESPLIT] def has_remote_branch? ( branch ) out = execute ( \"git ls-remote --heads\" ) out . split ( \"\\n\" ) . each do | l | return true if l . split ( / \\s / ) [ 1 ] == \"refs/heads/#{branch}\" end false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns the SHA - 1 representation of rev [CODESPLIT] def rev_sha1 ( rev ) sha1 = nil execute \"git rev-list -n 1 #{rev} --\" do | out , e | sha1 = out . strip if ! e end sha1 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns some informations about a revision [CODESPLIT] def rev_infos ( rev , desired ) info = { } desired . each_pair do | key , value | execute \"git log -1 --format=#{value} #{rev} --\" do | out , e | info [ key ] = out . strip if ! e end end info end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns the SHA - 1 representations of the heads of all remote branches [CODESPLIT] def remote_branch_revs out = execute \"git show-ref\" out . split ( \"\\n\" ) . collect { | l | if l =~ / \\/ \\/ / l . split [ 0 ] else nil end } . compact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "export file contents of rev to dir if + paths + is given and non - empty checks out only those parts of the filesystem tree does not remove any files from dir which existed before [CODESPLIT] def export_rev ( rev , dir , paths = [ ] ) paths = paths . dup loop do path_args = \"\" # max command line length on Windows XP and higher is 8191\r # consider the following extra characters which will be added:\r # up to 3 paths in execute, 1 path for tar, max path length 260 = 1040\r # plus some \"glue\" characters, plus the last path item with 260 max;\r # use 6000 to be on the safe side\r while ! paths . empty? && path_args . size < 6000 path_args << \" \" path_args << paths . shift end execute \"git archive --format tar #{rev} #{path_args} | tar -C #{dir} -xf -\" break if paths . empty? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "checks out rev to a temporary directory and yields this directory to the given block if + paths + is given and non - empty checks out only those parts of the filesystem tree returns the value returned by the block [CODESPLIT] def within_exported_rev ( rev , paths = [ ] ) Dir . mktmpdir ( \"rim\" ) do | d | d = Dir . glob ( d ) [ 0 ] c = File . join ( d , \"content\" ) FileUtils . mkdir ( c ) export_rev ( rev , c , paths ) # return contents of yielded block\r # mktmpdir returns value return by our block\r yield c FileUtils . rm_rf ( c ) # retry to delete if it hasn't been deleted yet\r # this could be due to Windows keeping the files locked for some time\r # this is especially a problem if the machine is at its limits\r retries = 600 while File . exist? ( c ) && retries > 0 sleep ( 0.1 ) FileUtils . rm_rf ( c ) retries -= 1 end if File . exist? ( c ) @logger . warn \"could not delete temp dir: #{c}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns a list of all files which changed in commit + rev + together with the kind of the change ( : modified : deleted : added ) [CODESPLIT] def changed_files ( rev , rev_from = nil ) out = execute \"git diff-tree -r --no-commit-id #{rev_from} #{rev}\" out . split ( \"\\n\" ) . collect do | l | cols = l . split path = cols [ 5 ] kind = case cols [ 4 ] when \"M\" :modified when \"A\" :added when \"D\" :deleted else nil end ChangedFile . new ( path , kind ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "upload all module changes into corresponding remote repositories [CODESPLIT] def upload # get the name of the current workspace branch RIM :: git_session ( @ws_root ) do | s | branch = s . current_branch if branch . nil? raise RimException . new ( \"Not on a git branch.\" ) elsif ! branch . start_with? ( \"rim/\" ) begin sha1 = s . rev_sha1 ( branch ) @logger . info ( \"Uploading modules...\" ) upload_modules ( get_upload_revisions ( s , sha1 ) ) ensure s . execute ( \"git checkout -B #{branch}\" ) end else raise RimException . new ( \"The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "upload all modules [CODESPLIT] def upload_modules ( info ) each_module_parallel ( \"uploading\" , @module_helpers ) do | m | m . upload ( info . parent , info . sha1s ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "get revisions to upload i . e . the revisions up to the last remote revision the function returns the revisions in order of appearal i . e . the oldest first [CODESPLIT] def get_upload_revisions ( session , rev ) # remote revs are where we stop traversal non_remote_revs = { } session . all_reachable_non_remote_revs ( rev ) . each do | r | non_remote_revs [ r ] = true end revisions = [ ] # make sure we deal only with sha1s rev = session . rev_sha1 ( rev ) while rev && non_remote_revs [ rev ] revisions . push ( rev ) parents = session . parent_revs ( rev ) rev = parents . size > 0 ? parents . first : nil end Struct . new ( :parent , :sha1s ) . new ( rev , revisions . reverse! ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fetch module + mod + into the . rim folder works both for initial fetch and updates [CODESPLIT] def fetch_module FileUtils . mkdir_p git_path RIM :: git_session ( git_path ) do | s | if ! File . exist? ( git_path + \"/config\" ) s . execute ( \"git clone --mirror #{@remote_url} #{git_path}\" ) do | out , e | raise RimException . new ( \"Remote repository '#{@remote_url}' of module '#{@module_info.local_path}' not found.\" ) if e end else s . execute ( \"git remote update\" ) end end git_path end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "prepare empty folder : remove all files not on the ignore list and empty folders [CODESPLIT] def prepare_empty_folder ( local_path , ignores ) ignores = FileHelper . find_matching_files ( local_path , true , ignores ) FileHelper . find_matching_files ( local_path , true , \"/**/*\" , File :: FNM_DOTMATCH ) . each do | f | if File . file? ( f ) && ! ignores . include? ( f ) FileUtils . rm ( f ) end end FileHelper . remove_empty_dirs ( local_path ) FileUtils . mkdir_p ( local_path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def determine_role ( args ) args [ : atc ] == false ? role = pilot : role = all args [ : pilots ] == false ? role = atc : role = role role = all if args [ : pilots ] == false && args [ : atc ] == false role end [CODESPLIT] def stations stations = [ ] CSV . foreach ( LOCAL_DATA , :col_sep => ':' ) do | row | callsign , origin , destination , client = row [ 0 ] . to_s , row [ 11 ] . to_s , row [ 13 ] . to_s , row [ 3 ] . to_s for cs in @callsign stations << row if callsign [ 0 ... cs . length ] == cs # && client == \"ATC\") unless @role == \"pilot\" # stations << row if (origin[0...icao.length] == icao || destination[0...icao.length] == icao) unless @role == \"atc\" end end stations end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assign the value to the given attribute of the item [CODESPLIT] def assign ( attribute , value ) unless value == :skip || attribute == :class if item . respond_to? ( \"#{attribute}=\" ) item . send ( \"#{attribute}=\" , value ) elsif item . is_a? ( Hash ) item [ attribute ] = value end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Nicked from here : http : // gist . github . com / 301173 [CODESPLIT] def get_constant ( name_sym ) return name_sym if name_sym . is_a? Class name = name_sym . to_s . split ( '_' ) . collect { | s | s . capitalize } . join ( '' ) Object . const_defined? ( name ) ? Object . const_get ( name ) : Object . const_missing ( name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Can be left in your tests as an alternative to build and to warn if your factory method ever starts producing invalid instances [CODESPLIT] def debug ( * args ) item = build ( args ) invalid_item = Array ( item ) . find ( :invalid? ) if invalid_item if invalid_item . errors . respond_to? ( :messages ) errors = invalid_item . errors . messages else errors = invalid_item . errors end raise \"Oops, the #{invalid_item.class} created by the Factory has the following errors: #{errors}\" end item end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Look for errors in factories and ( optionally ) their traits . Parameters : factory_names - which factories to lint ; omit for all factories options : traits : true - to lint traits as well as factories [CODESPLIT] def lint! ( factory_names : nil , traits : false ) factories_to_lint = Array ( factory_names || self . factory_names ) strategy = traits ? :factory_and_traits : :factory Linter . new ( self , factories_to_lint , strategy ) . lint! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute the requested factory method crank out the target object! [CODESPLIT] def crank_it ( what , overrides ) if what . to_s =~ / / what = $1 overrides = overrides . merge ( :_return_attributes => true ) end item = \"TBD\" new_job ( what , overrides ) do item = self . send ( what ) # Invoke the factory method item = apply_traits ( what , item ) end item end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Send missing methods to view_context first [CODESPLIT] def method_missing ( method , * args , & block ) if view_context . respond_to? ( method , true ) view_context . send ( method , args , block ) else super end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrap an object or collection of objects with a presenter class . [CODESPLIT] def present ( object , presenter : nil , ** args ) if object . respond_to? ( :to_ary ) object . map { | item | present ( item , presenter : presenter , ** args ) } else presenter ||= presenter_klass ( object ) wrapper = presenter . new ( object , view_context , ** args ) block_given? ? yield ( wrapper ) : wrapper end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build booking [CODESPLIT] def build_booking ( params = { } , template_code = nil ) template_code ||= self . class . to_s . underscore + ':invoice' booking_template = BookingTemplate . find_by_code ( template_code ) # Prepare booking parameters booking_params = { reference : self } booking_params . merge! ( params ) # Build and assign booking booking = booking_template . build_booking ( booking_params ) bookings << booking booking end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Supported options : : tag_prefix - use a custom prefix for Git tags ( defaults to v ) Publish the gem if its version has changed since the last release . [CODESPLIT] def publish_if_updated ( method , options = { } ) return if version_released? @builder . build ( @gemspec ) . tap { | gem | @pusher . push gem , method , options @git_remote . add_tag \"#{@tag_prefix}#{@version}\" } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Publish the gem . [CODESPLIT] def push ( gem , method , options = { } ) push_command = PUSH_METHODS [ method . to_s ] or raise \"Unknown Gem push method #{method.inspect}.\" push_command += [ gem ] push_command += [ \"--as\" , options [ :as ] ] if options [ :as ] @cli_facade . execute ( push_command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Disc s #enqueue is the main user - facing method of a Disc job it enqueues a job with a given set of arguments in Disque so it can be picked up by a Disc worker process . [CODESPLIT] def enqueue ( args = [ ] , at : nil , queue : nil , ** options ) options = disc_options . merge ( options ) . tap do | opt | opt [ :delay ] = at . to_time . to_i - DateTime . now . to_time . to_i unless at . nil? end disque . push ( queue || self . queue , Disc . serialize ( { class : self . name , arguments : Array ( args ) } ) , Disc . disque_timeout , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Constructor for all One Dimensional interpolation operations . [CODESPLIT] def interpolate interpolant case @opts [ :type ] when :linear for_each ( interpolant ) { | x | linear_interpolation ( x ) } when :cubic cubic_spline_interpolation interpolant else raise ArgumentError , \"1 D interpolation of type #{@opts[:type]} not supported\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Linear interpolation functions [CODESPLIT] def for_each interpolant result = [ ] if interpolant . kind_of? Numeric return yield interpolant else interpolant . each { | x | result << yield ( x ) } end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "References : Numerical Recipes Edition 3 . Chapter 3 . 3 [CODESPLIT] def compute_second_derivatives_for y y_sd = Array . new ( @size ) n = y_sd . size u = Array . new ( n - 1 ) yp1 = @opts [ :yp1 ] # first derivative of the 0th point as specified by the user ypn = @opts [ :ypn ] # first derivative of the nth point as specified by the user qn , un = nil , nil if yp1 > 0.99E30 y_sd [ 0 ] , u [ 0 ] = 0.0 , 0.0 else y_sd [ 0 ] = - 0.5 u [ 0 ] = ( 3.0 / ( @x [ 1 ] - @x [ 0 ] ) ) * ( ( y [ 1 ] - y [ 0 ] ) / ( @x [ 1 ] - @x [ 0 ] ) - yp1 ) end 1 . upto ( n - 2 ) do | i | # decomposition loop for tridiagonal algorithm sig = ( @x [ i ] - @x [ i - 1 ] ) / ( @x [ i + 1 ] - @x [ i - 1 ] ) p = sig * y_sd [ i - 1 ] + 2 y_sd [ i ] = ( sig - 1 ) / p u [ i ] = ( ( y [ i + 1 ] - y [ i ] ) / ( @x [ i + 1 ] - @x [ i ] ) ) - ( ( y [ i ] - y [ i - 1 ] ) / ( @x [ i ] - @x [ i - 1 ] ) ) u [ i ] = ( 6 * u [ i ] / ( @x [ i + 1 ] - @x [ i - 1 ] ) - sig * u [ i - 1 ] ) / p ; end if ypn > 0.99E30 qn , un = 0.0 , 0.0 else qn = 0.5 un = ( 3.0 / ( @x [ n - 1 ] - @x [ n - 2 ] ) ) * ( ypn - ( y [ n - 1 ] - y [ n - 2 ] ) / ( @x [ n - 1 ] - @x [ n - 2 ] ) ) end y_sd [ n - 1 ] = ( un - qn * u [ n - 2 ] ) / ( qn * y_sd [ n - 2 ] + 1.0 ) ( n - 2 ) . downto ( 0 ) do | k | y_sd [ k ] = y_sd [ k ] * y_sd [ k + 1 ] + u [ k ] end y_sd end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Reads the specified file as individual lines filters them using the * selector * ( if provided ) and returns those lines in an array . [CODESPLIT] def read_lines ( filename , selector ) if selector IO . foreach ( filename ) . select . with_index ( 1 , selector ) else open ( filename , :read ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds and initializes a lines selector that can handle the specified include . [CODESPLIT] def lines_selector_for ( target , attributes ) if ( klass = @selectors . find { | s | s . handles? target , attributes } ) klass . new ( target , attributes , logger : logger ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param attributes [ Hash<String String > ] the attributes parsed from the include :: [] s attributes slot . It must contain a key lines . Returns true if the given line should be included false otherwise . [CODESPLIT] def include? ( _ , line_num ) return false if @ranges . empty? ranges = @ranges ranges . pop while ! ranges . empty? && ranges . last . last < line_num ranges . last . cover? ( line_num ) if ! ranges . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param target [ String ] name of the source file to include as specified in the target slot of the include :: [] directive . @param attributes [ Hash<String String > ] the attributes parsed from the include :: [] s attributes slot . It must contain a key tag or tags . @param logger [ Logger ] Returns true if the given line should be included false otherwise . [CODESPLIT] def include? ( line , line_num ) tag_type , tag_name = parse_tag_directive ( line ) case tag_type when :start enter_region! ( tag_name , line_num ) false when :end exit_region! ( tag_name , line_num ) false when nil if @state && @first_included_lineno . nil? @first_included_lineno = line_num end @state end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates a <body > tag with HTML5 data attributes for the controller & action name . The keyword arguments are forwarded to tag and content_tag . [CODESPLIT] def body_tag ( params_as_metadata : false , ** kwargs ) options = kwargs . deep_merge ( data : data_attrs ( params_as_metadata ) ) if block_given? content_tag ( :body , options ) { yield } else tag ( :body , options , true ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Establishes a connection to the database that s used by all Active Record objects [CODESPLIT] def ovirt_legacy_postgresql_connection ( config ) conn_params = config . symbolize_keys conn_params . delete_if { | _ , v | v . nil? } # Map ActiveRecords param names to PGs. conn_params [ :user ] = conn_params . delete ( :username ) if conn_params [ :username ] conn_params [ :dbname ] = conn_params . delete ( :database ) if conn_params [ :database ] # Forward only valid config params to PGconn.connect. valid_conn_param_keys = PGconn . conndefaults_hash . keys + [ :requiressl ] conn_params . slice! ( valid_conn_param_keys ) # The postgres drivers don't allow the creation of an unconnected PGconn object, # so just pass a nil connection object for the time being. ConnectionAdapters :: OvirtLegacyPostgreSQLAdapter . new ( nil , logger , conn_params , config ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal methods : Append data as query params to an endpoint [CODESPLIT] def do_request method , action , query = { } url = @neto_url options = { } header_action = { \"NETOAPI_ACTION\" => action } #set headers options [ :headers ] = @header_args . merge ( header_action ) #set body case action when 'GetItem' if query . empty? options . merge! ( body : { \"Filter\" => @body_defaults } . to_json ) else body_args = @body_defaults . merge ( query ) options . merge! ( body : { \"Filter\" => body_args } . to_json ) end when 'AddItem' options . merge! ( body : { \"Item\" => [ query ] } . to_json ) when 'UpdateItem' options . merge! ( body : { \"Item\" => [ query ] } . to_json ) end HTTParty . send ( method , url , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Works just like the standard rand () function . If called with an integer argument rand () will return positive random number in the range of 0 to ( argument - 1 ) . If called without an integer argument rand () returns a positive floating point number less than 1 . If called with a Range returns a number that is in the range . [CODESPLIT] def rand ( arg = nil ) if @randcnt == 1 isaac @randcnt = 256 end @randcnt -= 1 if arg . nil? ( @randrsl [ @randcnt ] / 536_870_912.0 ) % 1 elsif arg . is_a? ( Integer ) @randrsl [ @randcnt ] % arg elsif arg . is_a? ( Range ) arg . min + @randrsl [ @randcnt ] % ( arg . max - arg . min ) else @randrsl [ @randcnt ] % arg . to_i end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Style / Semicolon [CODESPLIT] def isaac i = 0 @cc += 1 @bb += @cc @bb &= 0xffffffff while i < 256 x = @mm [ i ] @aa = ( @mm [ ( i + 128 ) & 255 ] + ( @aa ^ ( @aa << 13 ) ) ) & 0xffffffff @mm [ i ] = y = ( @mm [ ( x >> 2 ) & 255 ] + @aa + @bb ) & 0xffffffff @randrsl [ i ] = @bb = ( @mm [ ( y >> 10 ) & 255 ] + x ) & 0xffffffff i += 1 x = @mm [ i ] @aa = ( @mm [ ( i + 128 ) & 255 ] + ( @aa ^ ( 0x03ffffff & ( @aa >> 6 ) ) ) ) & 0xffffffff @mm [ i ] = y = ( @mm [ ( x >> 2 ) & 255 ] + @aa + @bb ) & 0xffffffff @randrsl [ i ] = @bb = ( @mm [ ( y >> 10 ) & 255 ] + x ) & 0xffffffff i += 1 x = @mm [ i ] @aa = ( @mm [ ( i + 128 ) & 255 ] + ( @aa ^ ( @aa << 2 ) ) ) & 0xffffffff @mm [ i ] = y = ( @mm [ ( x >> 2 ) & 255 ] + @aa + @bb ) & 0xffffffff @randrsl [ i ] = @bb = ( @mm [ ( y >> 10 ) & 255 ] + x ) & 0xffffffff i += 1 x = @mm [ i ] @aa = ( @mm [ ( i + 128 ) & 255 ] + ( @aa ^ ( 0x0000ffff & ( @aa >> 16 ) ) ) ) & 0xffffffff @mm [ i ] = y = ( @mm [ ( x >> 2 ) & 255 ] + @aa + @bb ) & 0xffffffff @randrsl [ i ] = @bb = ( @mm [ ( y >> 10 ) & 255 ] + x ) & 0xffffffff i += 1 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a Core object . [CODESPLIT] def run client_ip = @ip key = \"request_count:#{client_ip}\" result = { status : Constants :: SUCCESS_STATUS , message : Constants :: OK_MESSAGE } requests_count = @storage . get ( key ) unless requests_count @storage . set ( key , 0 ) @storage . expire ( key , @limits [ \"time_period_seconds\" ] ) end if requests_count . to_i >= @limits [ \"max_requests_count\" ] result [ :status ] = Constants :: EXPIRED_STATUS result [ :message ] = message ( period ( key ) ) else @storage . incr ( key ) end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a set of radio buttons . Takes a method name an array of choices ( just like a + select + field ) and an Informant options hash . [CODESPLIT] def radio_buttons ( method , choices , options = { } ) choices . map! { | i | i . is_a? ( Array ) ? i : [ i ] } build_shell ( method , options , \"radio_buttons_field\" ) do choices . map { | c | radio_button method , c [ 1 ] , :label => c [ 0 ] , :label_for => [ object_name , method , c [ 1 ] . to_s . downcase ] . join ( '_' ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a set of check boxes for selecting HABTM - associated objects . Takes a method name ( eg category_ids ) an array of choices ( just like a + select + field ) and an Informant options hash . In the default template the check boxes are enclosed in a <div > with CSS class <tt > habtm_check_boxes< / tt > which can be styled thusly to achieve a scrolling list : [CODESPLIT] def habtm_check_boxes ( method , choices , options = { } ) choices . map! { | i | i . is_a? ( Array ) ? i : [ i ] } base_id = \"#{object_name}_#{method}\" base_name = \"#{object_name}[#{method}]\" @template . hidden_field_tag ( \"#{base_name}[]\" , \"\" , :id => \"#{base_id}_empty\" ) + build_shell ( method , options , \"habtm_check_boxes_field\" ) do choices . map do | c | field_id = \"#{base_id}_#{c[1].to_s.downcase}\" habtm_single_check_box_template ( :name => \"#{base_name}[]\" , :id => field_id , :value => c [ 1 ] , :checked => @object . send ( method ) . include? ( c [ 1 ] ) , :label => @template . label_tag ( field_id , c [ 0 ] ) ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Standard Rails date selector . [CODESPLIT] def date_select ( method , options = { } ) options [ :include_blank ] ||= false options [ :start_year ] ||= 1801 options [ :end_year ] ||= Time . now . year options [ :label_for ] = \"#{object_name}_#{method}_1i\" build_shell ( method , options ) { super } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This differs from the Rails - default date_select in that it submits three distinct fields for storage in three separate attributes . This allows for partial dates ( eg 1984 or October 1984 ) . See { FlexDate } [ http : // github . com / alexreisner / flex_date ] for storing and manipulating partial dates . [CODESPLIT] def multipart_date_select ( method , options = { } ) options [ :include_blank ] ||= false options [ :start_year ] ||= 1801 options [ :end_year ] ||= Time . now . year options [ :prefix ] = object_name # for date helpers options [ :label_for ] = \"#{object_name}_#{method}_y\" build_shell ( method , options ) do [ [ 'y' , 'year' ] , [ 'm' , 'month' ] , [ 'd' , 'day' ] ] . map { | p | i , j = p value = @object . send ( method . to_s + '_' + i ) options [ :field_name ] = method . to_s + '_' + i eval ( \"@template.select_#{j}(#{value.inspect}, options)\" ) } . join ( ' ' ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Year select field . Takes options <tt > : start_year< / tt > and <tt > : end_year< / tt > and <tt > : step< / tt > . [CODESPLIT] def year_select ( method , options = { } ) options [ :first ] = options [ :start_year ] || 1801 options [ :last ] = options [ :end_year ] || Date . today . year integer_select ( method , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Integer select field . Takes options <tt > : first< / tt > <tt > : last< / tt > and <tt > : step< / tt > . [CODESPLIT] def integer_select ( method , options = { } ) options [ :step ] ||= 1 choices = [ ] ; i = 0 ( options [ :first ] .. options [ :last ] ) . each do | n | choices << n if i % options [ :step ] == 0 i += 1 end select method , choices , options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Submit button with smart default text ( if + value + is nil uses Create for new record or Update for old record ) . [CODESPLIT] def submit ( value = nil , options = { } ) value = ( @object . new_record? ? \"Create\" : \"Update\" ) if value . nil? build_shell ( value , options , 'submit_button' ) { super } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a field label . [CODESPLIT] def label ( method , text = nil , options = { } ) colon = false if options [ :colon ] . nil? options [ :for ] = options [ :label_for ] required = options [ :required ] # remove special options options . delete :colon options . delete :label_for options . delete :required text = @template . send ( :h , text . blank? ? method . to_s . humanize : text . to_s ) text << ':' . html_safe if colon text << @template . content_tag ( :span , \"*\" , :class => \"required\" ) if required super end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a field set ( HTML <fieldset > ) . Takes the legend ( optional ) an options hash and a block in which fields are rendered . [CODESPLIT] def field_set ( legend = nil , options = nil , & block ) @template . content_tag ( :fieldset , options ) do ( legend . blank? ? \"\" : @template . content_tag ( :legend , legend ) ) + @template . capture ( block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "--------------------------------------------------------------- [CODESPLIT] def build_shell ( method , options , template = 'default_field' ) #:nodoc: # Build new options hash for custom label options. label_options = options . reject { | i , j | ! @@custom_label_options . include? i } # Build new options hash for custom field options. field_options = options . reject { | i , j | ! @@custom_field_options . include? i } # Remove custom options from options hash so things like # <tt>include_blank</tt> aren't added as HTML attributes. options . reject! { | i , j | @@custom_options . include? i } locals = { :element => yield , :label => label ( method , field_options [ :label ] , label_options ) , :description => field_options [ :description ] , :div_id => \"#{@object_name}_#{method}_field\" , :required => field_options [ :required ] , :decoration => field_options [ :decoration ] || nil } send ( \"#{template}_template\" , locals ) . html_safe end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Render a group of HABTM check boxes . [CODESPLIT] def habtm_check_boxes_field_template ( l = { } ) <<-END #{ l [ :div_id ] } #{ l [ :label ] } #{ l [ :element ] . join } #{ l [ :decoration ] } #{ \"<p class=\\\"field_description\\\">#{l[:description]}</p>\" unless l [ :description ] . blank? } END end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called when parsing . While you can override this in subclasses in general it is probably better to use the on_unpack method to define a proc to handle unpacking for special cases . [CODESPLIT] def read ( raw , predecessors = nil ) if raw . respond_to? ( :read ) raw = raw . read ( self . sizeof ( ) ) end if raw . size < self . sizeof ( ) raise ( ReadError , \"Expected #{self.sizeof} bytes, but only got #{raw.size} bytes\" ) end vals = if @unpack_cb @unpack_cb . call ( raw , predecessors ) else raw . unpack ( self . format ) end return ( self . claim_value ( vals , predecessors ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called when composing raw data . While you can override this in subclasses in general it is probably better to use the on_pack method to define a proc to handle packing for special cases . [CODESPLIT] def pack_value ( val , obj = nil ) begin if @pack_cb @pack_cb . call ( val , obj ) else varray = val . is_a? ( Array ) ? val : [ val ] varray . pack ( self . format ) end rescue => e raise ( PackError , \"Error packing #{val.inspect} as type #{self.name.inspect} -- #{e.class} -> #{e}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Take the following C struct for example : [CODESPLIT] def struct ( name , opts = { } , & block ) Rstruct :: Structure . new ( name , opts , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Image resize [CODESPLIT] def ires_tag ( path , width : nil , height : nil , type : Type :: ALL , mode : Mode :: RESIZE , expire : 30 . days , ** option ) image_path = Ires :: Service . path ( path , width : width || 0 , height : height || 0 , mode : mode , type : type , expire : expire ) # Set image_tag image_tag ( image_path , option ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replacing RSpec s default method_missing implementation so that we can include our own special default hooks that allows spec tests to look more readable . [CODESPLIT] def method_missing ( sym , * args , & block ) # # Note: Be sure that the symbol does not contain the word \"test\". test # is a private method on Ruby objects and will cause the Be and Has # matches to fail. # return Lebowski :: RSpec :: Matchers :: Be . new ( sym , args ) if sym . to_s =~ / / return Lebowski :: RSpec :: Matchers :: Has . new ( sym , args ) if sym . to_s =~ / / return Lebowski :: RSpec :: Operators :: That . new ( sym , args ) if sym . to_s =~ / / super end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method searches for folders and files in the assets root directory . After searching all files stores in an array and then copying to the folder _site . [CODESPLIT] def static_files source = File . dirname ( ENGINE . assets_path ) asset_files . map do | file | dir = File . dirname ( file ) file_name = File . basename ( file ) Jekyll :: StaticFile . new @site , source , dir , file_name end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get paths and fils directory assets [CODESPLIT] def asset_files asset_files = [ ] Find . find ( ENGINE . assets_path ) . each do | path | next if File . directory? ( path ) next if path . include? ( ENGINE . stylesheets_sass_path ) asset_files << path . sub ( ENGINE . assets_path , 'assets' ) end asset_files end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "high level functions [CODESPLIT] def daily ( time = Date . today , page_size = 50 ) time = time . strftime ( \"%Y-%m-%d\" ) unless time . is_a? ( String ) report_id = run_report_request ( 'DailyActivityReport' , { 'report_date' => time } , page_size ) meta_data = get_meta_data_request ( report_id ) data = [ ] meta_data [ \"numberOfPages\" ] . to_i . times do | page_num | data += get_data_request ( report_id , page_num + 1 ) #it's zero indexed end data end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "low level functions [CODESPLIT] def run_report_request ( report_name , report_params = { } , page_size = 50 ) response = request 'runReportRequest' do | xml | xml . reportName report_name report_params . each do | name , value | xml . reportParam do xml . paramName name xml . paramValue value end end xml . pageSize page_size end response . elements [ \"runReportResponse/reportId\" ] . get_text . value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a unique field [CODESPLIT] def generate_unique ( length = 32 , & blk ) unique = generate_random ( length ) unique = generate_random ( length ) until blk . call ( unique ) unique end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "High level method to draw the paperback content on the pdf document [CODESPLIT] def draw_paperback ( qr_code : , sixword_lines : , sixword_bytes : , labels : , passphrase_sha : nil , passphrase_len : nil , sixword_font_size : nil , base64_content : nil , base64_bytes : nil ) unless qr_code . is_a? ( RQRCode :: QRCode ) raise ArgumentError . new ( 'qr_code must be RQRCode::QRCode' ) end # Header & QR code page pdf . font ( 'Times-Roman' ) debug_draw_axes draw_header ( labels : labels , passphrase_sha : passphrase_sha , passphrase_len : passphrase_len ) add_newline draw_qr_code ( qr_modules : qr_code . modules ) pdf . stroke_color '000000' pdf . fill_color '000000' # Sixword page pdf . start_new_page draw_sixword ( lines : sixword_lines , sixword_bytes : sixword_bytes , font_size : sixword_font_size , is_encrypted : passphrase_len ) if base64_content draw_base64 ( b64_content : base64_content , b64_bytes : base64_bytes , is_encrypted : passphrase_len ) end pdf . number_pages ( '<page> of <total>' , align : :right , at : [ pdf . bounds . right - 100 , - 2 ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates a glob file pattern for the specified list of locales ( i . e . IETF language tags ) [CODESPLIT] def pattern_from ( locales ) locales = Array ( locales || [ ] ) locales = locales . map { | locale | subpatterns_from locale } . flatten pattern = locales . blank? ? '*' : \"{#{locales.join ','}}\" \"#{base_pattern}#{pattern}#{extension}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates subpatterns for the specified locale ( i . e . IETF language tag ) . Subpatterns are all more generic variations of a locale . E . g . subpatterns for en - US are en - US and en . Subpatterns for az - Latn - IR are az - Latn - IR az - Latn and az [CODESPLIT] def subpatterns_from ( locale ) parts = locale . to_s . split ( '-' ) parts . map . with_index { | part , index | parts [ 0 .. index ] . join ( '-' ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Produces and processes a report for use in the report method It takes the same arguments as report and returns the same object as process_report [CODESPLIT] def produce_report ( * args ) # Check xcov availability, install it if needed ` ` unless xcov_available? unless xcov_available? puts \"xcov is not available on this machine\" return end require \"xcov\" require \"fastlane_core\" # Init Xcov config = FastlaneCore :: Configuration . create ( Xcov :: Options . available_options , convert_options ( args . first ) ) Xcov . config = config Xcov . ignore_handler = Xcov :: IgnoreHandler . new # Init project manager = Xcov :: Manager . new ( config ) # Parse .xccoverage report_json = manager . parse_xccoverage # Map and process report process_report ( Xcov :: Report . map ( report_json ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Outputs a processed report with Danger [CODESPLIT] def output_report ( report ) # Create markdown report_markdown = report . markdown_value # Send markdown markdown ( report_markdown ) # Notify failure if minimum coverage hasn't been reached threshold = Xcov . config [ :minimum_coverage_percentage ] . to_i if ! threshold . nil? && ( report . coverage * 100 ) < threshold fail ( \"Code coverage under minimum of #{threshold}%\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Filters the files that haven t been modified in the current PR [CODESPLIT] def process_report ( report ) file_names = @dangerfile . git . modified_files . map { | file | File . basename ( file ) } file_names += @dangerfile . git . added_files . map { | file | File . basename ( file ) } report . targets . each do | target | target . files = target . files . select { | file | file_names . include? ( file . name ) } end report end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates the CRC16 checksum . [CODESPLIT] def update ( data ) data . each_byte do | b | b = revert_byte ( b ) if REVERSE_DATA @crc = ( ( @table [ ( ( @crc >> 8 ) ^ b ) & 0xff ] ^ ( @crc << 8 ) ) & 0xffff ) end return self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "class << self [CODESPLIT] def request ( http_verb , url , options = { } ) full_url = url + hash_to_params ( options ) handle ( access_token . request ( http_verb , full_url ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove accents downcase replace spaces and word start with * return list of normalized words [CODESPLIT] def normalize ActiveSupport :: Multibyte :: Chars . new ( self ) . mb_chars . normalize ( :kd ) . gsub ( / \\x00 \\x7F / , '' ) . downcase . to_s . gsub ( / / , ' ' ) . gsub ( / \\s / , '*' ) . gsub ( / / , '**' ) . gsub ( / / , '*' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Class macro used to associate an enum with an attribute on an ActiveRecord model . This method is added to an ActiveRecord model when ClassEnum :: ActiveRecord is included . Accepts an argument for the enum class to be associated with the model . ActiveRecord validation is automatically added to ensure that a value is one of its pre - defined enum members . [CODESPLIT] def classy_enum_attr ( attribute , options = { } ) enum = ( options [ :class_name ] || options [ :enum ] || attribute ) . to_s . camelize . constantize allow_blank = options [ :allow_blank ] || false allow_nil = options [ :allow_nil ] || false default = ClassyEnum . _normalize_default ( options [ :default ] , enum ) # Add ActiveRecord validation to ensure it won't be saved unless it's an option validates_inclusion_of attribute , in : enum , allow_blank : allow_blank , allow_nil : allow_nil # Use a module so that the reader methods can be overridden in classes and # use super to get the enum value. mod = Module . new do # Define getter method that returns a ClassyEnum instance define_method attribute do enum . build ( read_attribute ( attribute ) || super ( ) , owner : self ) end # Define setter method that accepts string, symbol, instance or class for member define_method \"#{attribute}=\" do | value | value = ClassyEnum . _normalize_value ( value , default , ( allow_nil || allow_blank ) ) super ( value ) end define_method :save_changed_attribute do | attr_name , arg | if attribute . to_s == attr_name . to_s && ! attribute_changed? ( attr_name ) arg = enum . build ( arg ) current_value = clone_attribute_value ( :read_attribute , attr_name ) if arg != current_value if respond_to? ( :set_attribute_was , true ) set_attribute_was ( attr_name , enum . build ( arg , owner : self ) ) else changed_attributes [ attr_name ] = enum . build ( current_value , owner : self ) end end else super ( attr_name , arg ) end end end include mod # Initialize the object with the default value if it is present # because this will let you store the default value in the # database and make it searchable. if default . present? after_initialize do value = read_attribute ( attribute ) || send ( attribute ) if ( value . blank? && ! ( allow_blank || allow_nil ) ) || ( value . nil? && ! allow_nil ) send ( \"#{attribute}=\" , default ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "belows are data types [CODESPLIT] def string ( opts = { } ) length , any , value = ( opts [ :length ] || 8 ) , opts [ :any ] , opts [ :value ] if value string = value . to_s Proc . new { string } elsif any Proc . new { self . any ( any ) } else Proc . new { Array . new ( length ) { @chars [ rand ( @chars . size - 1 ) ] } . join } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete an existing authorization . API calls using that token will stop working . API Path : / api / v2 / authorizations / : id == Parameters : id :: id [CODESPLIT] def authorization_delete ( id ) path = sprintf ( \"/api/v2/authorizations/%s\" , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"DELETE\" , path , reqHelper . ctype , reqHelper . body , 204 ) if err != nil return nil , err end return err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single authorization . API Path : / api / v2 / authorizations / : id == Parameters : id :: id [CODESPLIT] def authorization_show ( id ) path = sprintf ( \"/api/v2/authorizations/%s\" , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Authorization . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update an existing authorization . API Path : / api / v2 / authorizations / : id == Parameters : id :: id params :: Parameters of type PhraseApp :: RequestParams :: AuthorizationParams [CODESPLIT] def authorization_update ( id , params ) path = sprintf ( \"/api/v2/authorizations/%s\" , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: AuthorizationParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::AuthorizationParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"PATCH\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Authorization . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single rule for blacklisting keys for a given project . API Path : / api / v2 / projects / : project_id / blacklisted_keys / : id == Parameters : project_id :: project_id id :: id [CODESPLIT] def blacklisted_key_show ( project_id , id ) path = sprintf ( \"/api/v2/projects/%s/blacklisted_keys/%s\" , project_id , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: BlacklistedKey . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update an existing comment . API Path : / api / v2 / projects / : project_id / keys / : key_id / comments / : id == Parameters : project_id :: project_id key_id :: key_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: CommentParams [CODESPLIT] def comment_update ( project_id , key_id , id , params ) path = sprintf ( \"/api/v2/projects/%s/keys/%s/comments/%s\" , project_id , key_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: CommentParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::CommentParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"PATCH\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Comment . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List all glossaries the current user has access to . API Path : / api / v2 / accounts / : account_id / glossaries == Parameters : account_id :: account_id [CODESPLIT] def glossaries_list ( account_id , page , per_page ) path = sprintf ( \"/api/v2/accounts/%s/glossaries\" , account_id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request_paginated ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 , page , per_page ) if err != nil return nil , err end return JSON . load ( rc . body ) . map { | item | PhraseApp :: ResponseObjects :: Glossary . new ( item ) } , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new glossary . API Path : / api / v2 / accounts / : account_id / glossaries == Parameters : account_id :: account_id params :: Parameters of type PhraseApp :: RequestParams :: GlossaryParams [CODESPLIT] def glossary_create ( account_id , params ) path = sprintf ( \"/api/v2/accounts/%s/glossaries\" , account_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: GlossaryParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::GlossaryParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Glossary . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single glossary . API Path : / api / v2 / accounts / : account_id / glossaries / : id == Parameters : account_id :: account_id id :: id [CODESPLIT] def glossary_show ( account_id , id ) path = sprintf ( \"/api/v2/accounts/%s/glossaries/%s\" , account_id , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Glossary . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single glossary term . API Path : / api / v2 / accounts / : account_id / glossaries / : glossary_id / terms / : id == Parameters : account_id :: account_id glossary_id :: glossary_id id :: id [CODESPLIT] def glossary_term_show ( account_id , glossary_id , id ) path = sprintf ( \"/api/v2/accounts/%s/glossaries/%s/terms/%s\" , account_id , glossary_id , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: GlossaryTerm . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update an existing glossary term . API Path : / api / v2 / accounts / : account_id / glossaries / : glossary_id / terms / : id == Parameters : account_id :: account_id glossary_id :: glossary_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: GlossaryTermParams [CODESPLIT] def glossary_term_update ( account_id , glossary_id , id , params ) path = sprintf ( \"/api/v2/accounts/%s/glossaries/%s/terms/%s\" , account_id , glossary_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: GlossaryTermParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::GlossaryTermParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"PATCH\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: GlossaryTerm . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update an existing job locale . API Path : / api / v2 / projects / : project_id / jobs / : job_id / locales / : id == Parameters : project_id :: project_id job_id :: job_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: JobLocaleParams [CODESPLIT] def job_locale_update ( project_id , job_id , id , params ) path = sprintf ( \"/api/v2/projects/%s/jobs/%s/locales/%s\" , project_id , job_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: JobLocaleParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::JobLocaleParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"PATCH\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: JobLocale . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List all job locales for a given job . API Path : / api / v2 / projects / : project_id / jobs / : job_id / locales == Parameters : project_id :: project_id job_id :: job_id params :: Parameters of type PhraseApp :: RequestParams :: JobLocalesListParams [CODESPLIT] def job_locales_list ( project_id , job_id , page , per_page , params ) path = sprintf ( \"/api/v2/projects/%s/jobs/%s/locales\" , project_id , job_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: JobLocalesListParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::JobLocalesListParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request_paginated ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 , page , per_page ) if err != nil return nil , err end return JSON . load ( rc . body ) . map { | item | PhraseApp :: ResponseObjects :: JobLocale . new ( item ) } , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new key . API Path : / api / v2 / projects / : project_id / keys == Parameters : project_id :: project_id params :: Parameters of type PhraseApp :: RequestParams :: TranslationKeyParams [CODESPLIT] def key_create ( project_id , params ) path = sprintf ( \"/api/v2/projects/%s/keys\" , project_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: TranslationKeyParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::TranslationKeyParams\" ) end end if params . branch != nil data_hash [ \"branch\" ] = params . branch end if params . data_type != nil data_hash [ \"data_type\" ] = params . data_type end if params . description != nil data_hash [ \"description\" ] = params . description end if params . localized_format_key != nil data_hash [ \"localized_format_key\" ] = params . localized_format_key end if params . localized_format_string != nil data_hash [ \"localized_format_string\" ] = params . localized_format_string end if params . max_characters_allowed != nil data_hash [ \"max_characters_allowed\" ] = params . max_characters_allowed . to_i end if params . name != nil data_hash [ \"name\" ] = params . name end if params . name_plural != nil data_hash [ \"name_plural\" ] = params . name_plural end if params . original_file != nil data_hash [ \"original_file\" ] = params . original_file end if params . plural != nil data_hash [ \"plural\" ] = ( params . plural == true ) end if params . remove_screenshot != nil data_hash [ \"remove_screenshot\" ] = ( params . remove_screenshot == true ) end if params . screenshot != nil post_body = [ ] post_body << \"--#{PhraseApp::MULTIPART_BOUNDARY}\\r\\n\" post_body << \"Content-Disposition: form-data; name=\\\"screenshot\\\"; filename=\\\"#{File.basename(params.screenshot )}\\\"\\r\\n\" post_body << \"Content-Type: text/plain\\r\\n\" post_body << \"\\r\\n\" post_body << File . read ( params . screenshot ) post_body << \"\\r\\n\" end if params . tags != nil data_hash [ \"tags\" ] = params . tags end if params . unformatted != nil data_hash [ \"unformatted\" ] = ( params . unformatted == true ) end if params . xml_space_preserve != nil data_hash [ \"xml_space_preserve\" ] = ( params . xml_space_preserve == true ) end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: TranslationKeyDetails . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single key for a given project . API Path : / api / v2 / projects / : project_id / keys / : id == Parameters : project_id :: project_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: KeyShowParams [CODESPLIT] def key_show ( project_id , id , params ) path = sprintf ( \"/api/v2/projects/%s/keys/%s\" , project_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: KeyShowParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::KeyShowParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: TranslationKeyDetails . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new project . API Path : / api / v2 / projects == Parameters : params :: Parameters of type PhraseApp :: RequestParams :: ProjectParams [CODESPLIT] def project_create ( params ) path = sprintf ( \"/api/v2/projects\" ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: ProjectParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::ProjectParams\" ) end end if params . account_id != nil data_hash [ \"account_id\" ] = params . account_id end if params . main_format != nil data_hash [ \"main_format\" ] = params . main_format end if params . name != nil data_hash [ \"name\" ] = params . name end if params . project_image != nil post_body = [ ] post_body << \"--#{PhraseApp::MULTIPART_BOUNDARY}\\r\\n\" post_body << \"Content-Disposition: form-data; name=\\\"project_image\\\"; filename=\\\"#{File.basename(params.project_image )}\\\"\\r\\n\" post_body << \"Content-Type: text/plain\\r\\n\" post_body << \"\\r\\n\" post_body << File . read ( params . project_image ) post_body << \"\\r\\n\" end if params . remove_project_image != nil data_hash [ \"remove_project_image\" ] = ( params . remove_project_image == true ) end if params . shares_translation_memory != nil data_hash [ \"shares_translation_memory\" ] = ( params . shares_translation_memory == true ) end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: ProjectDetails . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new release . API Path : / api / v2 / accounts / : account_id / distributions / : distribution_id / releases == Parameters : account_id :: account_id distribution_id :: distribution_id params :: Parameters of type PhraseApp :: RequestParams :: ReleasesParams [CODESPLIT] def release_create ( account_id , distribution_id , params ) path = sprintf ( \"/api/v2/accounts/%s/distributions/%s/releases\" , account_id , distribution_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: ReleasesParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::ReleasesParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Release . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Publish a release for production . API Path : / api / v2 / accounts / : account_id / distributions / : distribution_id / releases / : id / publish == Parameters : account_id :: account_id distribution_id :: distribution_id id :: id [CODESPLIT] def release_publish ( account_id , distribution_id , id ) path = sprintf ( \"/api/v2/accounts/%s/distributions/%s/releases/%s/publish\" , account_id , distribution_id , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Release . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Update an existing screenshot . API Path : / api / v2 / projects / : project_id / screenshots / : id == Parameters : project_id :: project_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: ScreenshotParams [CODESPLIT] def screenshot_update ( project_id , id , params ) path = sprintf ( \"/api/v2/projects/%s/screenshots/%s\" , project_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: ScreenshotParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::ScreenshotParams\" ) end end if params . description != nil data_hash [ \"description\" ] = params . description end if params . filename != nil post_body = [ ] post_body << \"--#{PhraseApp::MULTIPART_BOUNDARY}\\r\\n\" post_body << \"Content-Disposition: form-data; name=\\\"filename\\\"; filename=\\\"#{File.basename(params.filename )}\\\"\\r\\n\" post_body << \"Content-Type: text/plain\\r\\n\" post_body << \"\\r\\n\" post_body << File . read ( params . filename ) post_body << \"\\r\\n\" end if params . name != nil data_hash [ \"name\" ] = params . name end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"PATCH\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Screenshot . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new screenshot marker . API Path : / api / v2 / projects / : project_id / screenshots / : screenshot_id / markers == Parameters : project_id :: project_id screenshot_id :: screenshot_id params :: Parameters of type PhraseApp :: RequestParams :: ScreenshotMarkerParams [CODESPLIT] def screenshot_marker_create ( project_id , screenshot_id , params ) path = sprintf ( \"/api/v2/projects/%s/screenshots/%s/markers\" , project_id , screenshot_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: ScreenshotMarkerParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::ScreenshotMarkerParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: ScreenshotMarker . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete an existing screenshot marker . API Path : / api / v2 / projects / : project_id / screenshots / : screenshot_id / markers == Parameters : project_id :: project_id screenshot_id :: screenshot_id [CODESPLIT] def screenshot_marker_delete ( project_id , screenshot_id ) path = sprintf ( \"/api/v2/projects/%s/screenshots/%s/markers\" , project_id , screenshot_id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"DELETE\" , path , reqHelper . ctype , reqHelper . body , 204 ) if err != nil return nil , err end return err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single screenshot marker for a given project . API Path : / api / v2 / projects / : project_id / screenshots / : screenshot_id / markers / : id == Parameters : project_id :: project_id screenshot_id :: screenshot_id id :: id [CODESPLIT] def screenshot_marker_show ( project_id , screenshot_id , id ) path = sprintf ( \"/api/v2/projects/%s/screenshots/%s/markers/%s\" , project_id , screenshot_id , id ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: ScreenshotMarker . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Show details for current User . API Path : / api / v2 / user == Parameters : [CODESPLIT] def show_user ( ) path = sprintf ( \"/api/v2/user\" ) data_hash = { } post_body = nil reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: User . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete an existing tag . API Path : / api / v2 / projects / : project_id / tags / : name == Parameters : project_id :: project_id name :: name params :: Parameters of type PhraseApp :: RequestParams :: TagDeleteParams [CODESPLIT] def tag_delete ( project_id , name , params ) path = sprintf ( \"/api/v2/projects/%s/tags/%s\" , project_id , name ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: TagDeleteParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::TagDeleteParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"DELETE\" , path , reqHelper . ctype , reqHelper . body , 204 ) if err != nil return nil , err end return err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Upload a new language file . Creates necessary resources in your project . API Path : / api / v2 / projects / : project_id / uploads == Parameters : project_id :: project_id params :: Parameters of type PhraseApp :: RequestParams :: UploadParams [CODESPLIT] def upload_create ( project_id , params ) path = sprintf ( \"/api/v2/projects/%s/uploads\" , project_id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: UploadParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::UploadParams\" ) end end if params . autotranslate != nil data_hash [ \"autotranslate\" ] = ( params . autotranslate == true ) end if params . branch != nil data_hash [ \"branch\" ] = params . branch end if params . convert_emoji != nil data_hash [ \"convert_emoji\" ] = ( params . convert_emoji == true ) end if params . file != nil post_body = [ ] post_body << \"--#{PhraseApp::MULTIPART_BOUNDARY}\\r\\n\" post_body << \"Content-Disposition: form-data; name=\\\"file\\\"; filename=\\\"#{File.basename(params.file )}\\\"\\r\\n\" post_body << \"Content-Type: text/plain\\r\\n\" post_body << \"\\r\\n\" post_body << File . read ( params . file ) post_body << \"\\r\\n\" end if params . file_encoding != nil data_hash [ \"file_encoding\" ] = params . file_encoding end if params . file_format != nil data_hash [ \"file_format\" ] = params . file_format end if params . format_options != nil params . format_options . each do | key , value | data_hash [ \"format_options\" ] [ key ] = value end end if params . locale_id != nil data_hash [ \"locale_id\" ] = params . locale_id end if params . locale_mapping != nil params . locale_mapping . each do | key , value | data_hash [ \"locale_mapping\" ] [ key ] = value end end if params . mark_reviewed != nil data_hash [ \"mark_reviewed\" ] = ( params . mark_reviewed == true ) end if params . skip_unverification != nil data_hash [ \"skip_unverification\" ] = ( params . skip_unverification == true ) end if params . skip_upload_tags != nil data_hash [ \"skip_upload_tags\" ] = ( params . skip_upload_tags == true ) end if params . tags != nil data_hash [ \"tags\" ] = params . tags end if params . update_descriptions != nil data_hash [ \"update_descriptions\" ] = ( params . update_descriptions == true ) end if params . update_translations != nil data_hash [ \"update_translations\" ] = ( params . update_translations == true ) end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"POST\" , path , reqHelper . ctype , reqHelper . body , 201 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: Upload . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details on a single version . API Path : / api / v2 / projects / : project_id / translations / : translation_id / versions / : id == Parameters : project_id :: project_id translation_id :: translation_id id :: id params :: Parameters of type PhraseApp :: RequestParams :: VersionShowParams [CODESPLIT] def version_show ( project_id , translation_id , id , params ) path = sprintf ( \"/api/v2/projects/%s/translations/%s/versions/%s\" , project_id , translation_id , id ) data_hash = { } post_body = nil if params . present? unless params . kind_of? ( PhraseApp :: RequestParams :: VersionShowParams ) raise PhraseApp :: ParamsHelpers :: ParamsError . new ( \"Expects params to be kind_of PhraseApp::RequestParams::VersionShowParams\" ) end end data_hash = params . to_h err = params . validate if err != nil return nil , err end reqHelper = PhraseApp :: ParamsHelpers :: BodyTypeHelper . new ( data_hash , post_body ) rc , err = PhraseApp . send_request ( @credentials , \"GET\" , path , reqHelper . ctype , reqHelper . body , 200 ) if err != nil return nil , err end return PhraseApp :: ResponseObjects :: TranslationVersionWithUser . new ( JSON . load ( rc . body ) ) , err end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts values on the basis of unified tag name and value . It is called each time a value is fethed from a Values instance . [CODESPLIT] def convert tag , val return val unless val . kind_of? ( String ) case tag when 'partofset' , 'track' return val end case val when REGEXP_TIMESTAMP year , month , day , hour , minute = $~ . captures [ 0 , 5 ] . map { | cap | cap . to_i } if month == 0 || day == 0 return nil end second = $6 . to_f zone = $7 zone = '+00:00' if zone == 'Z' Time . new ( year , month , day , hour , minute , second , zone ) when REGEXP_RATIONAL return val if $2 . to_i == 0 Rational ( $1 , $2 ) else val end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates a hash representation of this instance with original tag names es keys and converted values as values [CODESPLIT] def to_h @values . inject ( Hash . new ) do | h , a | tag , val = a h [ Values . tag_map [ tag ] ] = convert ( Values . unify_tag ( tag ) , val ) h end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Getting the command - line arguments which would be executed when calling #read . It could be useful for logging debugging or maybe even for creating a batch - file with exiftool command to be processed . [CODESPLIT] def exiftool_args fail MultiExiftool :: Error , 'No filenames.' if filenames . empty? cmd = [ ] cmd << Reader . mandatory_args cmd << options_args cmd << tags_args cmd << filenames cmd . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Getting the command - line arguments which would be executed when calling #write . It could be useful for logging debugging or maybe even for creating a batch - file with exiftool command to be processed . [CODESPLIT] def exiftool_args fail MultiExiftool :: Error , 'No filenames.' if filenames . empty? cmd = [ ] cmd << Writer . mandatory_args cmd << options_args cmd << values_args cmd << filenames cmd . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Private : Builds new instance of a CircuitBreaker . [CODESPLIT] def allow_request? instrument ( \"resilient.circuit_breaker.allow_request\" , key : @key ) { | payload | payload [ :result ] = if payload [ :force_open ] = @properties . force_open false else # we still want to simulate normal behavior/metrics like open, allow # single request, etc. so it is possible to test properties in # production without impact using force_closed so we run these here # instead of in the else below allow_request = ! open? || allow_single_request? if payload [ :force_closed ] = @properties . force_closed true else allow_request end end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Easy method to display a notification [CODESPLIT] def n ( msg , title = '' , image = nil ) Compat :: UI . notify ( msg , :title => title , :image => image ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Eager prints the result for stdout and stderr as it would be written when running the command from the terminal . This is useful for long running tasks . [CODESPLIT] def eager ( command ) require 'pty' begin PTY . spawn command do | r , w , pid | begin $stdout . puts r . each { | line | print line } rescue Errno :: EIO # the process has finished end end rescue PTY :: ChildExited $stdout . puts \"The child process exited!\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "an array of text [CODESPLIT] def wrap_list ( list , width ) list . map do | text | wrap_text ( text , width ) end . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "save the data to file [CODESPLIT] def save return if @data . empty? output = { } output [ :data ] = @data output [ :generated_at ] = Time . now . to_s output [ :started_at ] = @started_at output [ :format_version ] = '1.0' output [ :rails_version ] = Rails . version output [ :rails_path ] = Rails . root . to_s FileUtils . mkdir_p ( @config . output_path ) filename = \"sql_tracker-#{Process.pid}-#{Time.now.to_i}.json\" File . open ( File . join ( @config . output_path , filename ) , 'w' ) do | f | f . write JSON . dump ( output ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Split on \\ r \\ n or \\ n to get the lines unfold continued lines ( they start with or \\ t ) and return the array of unfolded lines . [CODESPLIT] def unfold ( card ) unfolded = [ ] prior_line = nil card . lines do | line | line . chomp! # If it's a continuation line, add it to the last. # If it's an empty line, drop it from the input. if line =~ / \\t / unfolded [ - 1 ] << line [ 1 , line . size - 1 ] elsif line =~ / / elsif prior_line && ( prior_line =~ UNTERMINATED_QUOTED_PRINTABLE ) # Strip the trailing = off prior line, then append current line unfolded [ - 1 ] = prior_line [ 0 , prior_line . length - 1 ] + line elsif line =~ / / else unfolded << line end prior_line = unfolded [ - 1 ] end unfolded end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a key / value to the map . [CODESPLIT] def []= ( key , value ) ObjectSpace . define_finalizer ( value , @reference_cleanup ) key = key . dup if key . is_a? ( String ) @lock . synchronize do @references [ key ] = self . class . reference_class . new ( value ) keys_for_id = @references_to_keys_map [ value . __id__ ] unless keys_for_id keys_for_id = [ ] @references_to_keys_map [ value . __id__ ] = keys_for_id end keys_for_id << key end value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove the entry associated with the key from the map . [CODESPLIT] def delete ( key ) ref = @references . delete ( key ) if ref keys_to_id = @references_to_keys_map [ ref . referenced_object_id ] if keys_to_id keys_to_id . delete ( key ) @references_to_keys_map . delete ( ref . referenced_object_id ) if keys_to_id . empty? end ref . object else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterate through all the key / value pairs in the map that have not been reclaimed by the garbage collector . [CODESPLIT] def each @references . each do | key , ref | value = ref . object yield ( key , value ) if value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a new struct containing the contents of other and the contents of self . If no block is specified the value for entries with duplicate keys will be that of other . Otherwise the value for each duplicate key is determined by calling the block with the key its value in self and its value in other . [CODESPLIT] def merge ( other_hash , & block ) to_h . merge ( other_hash , block ) . reduce ( self . class . new ) do | map , pair | map [ pair . first ] = pair . last map end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a strong reference to the object . This reference will live for three passes of the garbage collector . [CODESPLIT] def add_strong_reference ( obj ) #:nodoc: @@lock . synchronize do @@strong_references . last [ obj ] = true unless @@gc_flag_set @@gc_flag_set = true ObjectSpace . define_finalizer ( Object . new , @@finalizer ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This implementation of a weak reference simply wraps the standard WeakRef implementation that comes with the Ruby standard library . [CODESPLIT] def object #:nodoc: @ref . __getobj__ rescue => e # Jruby implementation uses RefError while MRI uses WeakRef::RefError if ( defined? ( RefError ) && e . is_a? ( RefError ) ) || ( defined? ( :: WeakRef :: RefError ) && e . is_a? ( :: WeakRef :: RefError ) ) nil else raise e end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a key / value to the map . [CODESPLIT] def []= ( key , value ) ObjectSpace . define_finalizer ( key , @reference_cleanup ) @lock . synchronize do @references_to_keys_map [ key . __id__ ] = self . class . reference_class . new ( key ) @values [ key . __id__ ] = value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove the value associated with the key from the map . [CODESPLIT] def delete ( key ) @lock . synchronize do rkey = ref_key ( key ) if rkey @references_to_keys_map . delete ( rkey ) @values . delete ( rkey ) else nil end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterate through all the key / value pairs in the map that have not been reclaimed by the garbage collector . [CODESPLIT] def each @references_to_keys_map . each do | rkey , ref | key = ref . object yield ( key , @values [ rkey ] ) if key end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Monitor a reference . When the object the reference points to is garbage collected the reference will be added to the queue . [CODESPLIT] def monitor ( reference ) obj = reference . object if obj @lock . synchronize do @references [ reference . referenced_object_id ] = reference end ObjectSpace . define_finalizer ( obj , @finalizer ) else push ( reference ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "curl - G - d - is &api_key = ed08eba2bd5ef47bab6cb1944686fed2&country = de&cat_id = 135&geo = 53 . 66 10 . 1154 https : // api . apphera . com / 1 / organizations Get a free api_key [CODESPLIT] def categories ( country ) begin results = Mash . new ( self . class . get ( '/categories' , :query => { :country => country } . merge ( self . default_options ) ) ) rescue => e key_error e end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Setup OAuth2 instance [CODESPLIT] def client ( options = { } ) @client ||= :: OAuth2 :: Client . new ( client_id , client_secret , { :site => options . fetch ( :site ) { Nimbu . site } , :authorize_url => 'login/oauth/authorize' , :token_url => 'login/oauth/access_token' , :ssl => { :verify => false } } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Default middleware stack that uses default adapter as specified at configuration stage . [CODESPLIT] def default_middleware ( options = { } ) Proc . new do | builder | unless options [ :with_attachments ] builder . use Nimbu :: Request :: Json end builder . use Faraday :: Request :: Multipart builder . use Faraday :: Request :: UrlEncoded builder . use Nimbu :: Request :: OAuth2 , oauth_token if oauth_token? builder . use Nimbu :: Request :: BasicAuth , authentication if basic_authed? builder . use Nimbu :: Request :: UserAgent builder . use Nimbu :: Request :: SiteHeader , subdomain builder . use Nimbu :: Request :: ContentLocale , content_locale builder . use Faraday :: Response :: Logger if ENV [ 'DEBUG' ] builder . use Nimbu :: Response :: RaiseError unless options [ :raw ] builder . use Nimbu :: Response :: Mashify builder . use Nimbu :: Response :: Json end builder . adapter adapter end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a Fraday :: Connection object [CODESPLIT] def connection ( options = { } ) conn_options = default_options ( options ) . keep_if { | k , _ | ALLOWED_OPTIONS . include? k } clear_cache unless options . empty? puts \"OPTIONS:#{conn_options.inspect}\" if ENV [ 'DEBUG' ] Faraday . new ( conn_options . merge ( :builder => stack ( options ) ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialise SmartAdapters delegator [CODESPLIT] def load unless valid_params? raise SmartAdapters :: Exceptions :: InvalidRequestParamsException end unless valid_format? raise SmartAdapters :: Exceptions :: InvalidRequestFormatException end adapter_finder . new ( request_manager ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find adapter for the given request ( resource action format ) [CODESPLIT] def adapter_finder resource = request_detail ( key : :controller ) req_action = request_detail ( key : :action ) req_format = request_format . symbol . to_s . camelize \"SmartAdapters::#{resource}::#{req_action}::#{req_format}Adapter\" . constantize end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "for standard errors this method build a hash [CODESPLIT] def error { error : { model : self . object [ \"model\" ] , model_human : self . object [ \"model_human\" ] , attribute : self . object [ \"attribute\" ] , attribute_human : self . object [ \"attribute_human\" ] , field : self . object [ \"field\" ] , message : self . object [ \"message\" ] , full_message : \"#{self.object[\"full_message\"]}\" } } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Configure options and process basic authorization [CODESPLIT] def setup ( options = { } ) options . each do | k , v | self . set ( k , v , true ) end options = Nimbu . options . merge ( options ) self . current_options = options Configuration . keys . each do | key | send ( \"#{key}=\" , options [ key ] ) end process_basic_auth ( options [ :basic_auth ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Acts as setter and getter for api requests arguments parsing . [CODESPLIT] def arguments ( args = ( not_set = true ) , options = { } , & block ) if not_set @arguments else @arguments = Arguments . new ( self , options ) . parse ( args , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Reset configuration options to their defaults [CODESPLIT] def reset! self . client_id = DEFAULT_CLIENT_ID self . client_secret = DEFAULT_CLIENT_SECRET self . oauth_token = DEFAULT_OAUTH_TOKEN self . endpoint = DEFAULT_ENDPOINT self . site = DEFAULT_SITE self . ssl = DEFAULT_SSL self . user_agent = DEFAULT_USER_AGENT self . connection_options = DEFAULT_CONNECTION_OPTIONS self . mime_type = DEFAULT_MIME_TYPE self . login = DEFAULT_LOGIN self . password = DEFAULT_PASSWORD self . basic_auth = DEFAULT_BASIC_AUTH self . auto_pagination = DEFAULT_AUTO_PAGINATION self . content_locale = DEFAULT_CONTENT_LOCALE self . adapter = DEFAULT_ADAPTER self . subdomain = DEFAULT_SUBDOMAIN self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse filter query parameters and partition into an { Array } . The first index will contain the valid filters and the second index will contain the invalid filters . [CODESPLIT] def parse_filters ( filter_query_params ) filter_query_params . map { | filter_string | begin MultiJson . load filter_string rescue MultiJson :: ParseError => ex \"#{ex} (filter: #{filter_string})\" end } . partition { | filter | filter . is_a? ( Hash ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve the filters that do not provide category name and value keys . [CODESPLIT] def incomplete_filters ( filters ) filters . select { | filter | [ 'category' , 'name' , 'value' ] . any? { | f | ! filter . include? f } } . map { | incomplete_filter | category , name , value = incomplete_filter . values_at ( 'category' , 'name' , 'value' ) error = <<-MSG . gsub ( / \\s / , '' ) . strip #{ category } #{ name } #{ value } MSG incomplete_filter . merge ( :error => error ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve the filters that represent invalid full - text search values . [CODESPLIT] def invalid_fts_filters ( filters ) filters . select { | filter | category , name , value = filter . values_at ( 'category' , 'name' , 'value' ) category == 'fts' && name == 'search' && value . to_s . length <= 1 } . map { | invalid_fts_filter | error = <<-MSG . gsub ( / \\s / , '' ) . strip MSG invalid_fts_filter . merge ( :error => error ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validate the requested filter query strings . If all filters are valid then return them as { Hash hashes } otherwise halt 400 Bad Request and return JSON error response . [CODESPLIT] def validate_filters! filter_query_params = CGI :: parse ( env [ \"QUERY_STRING\" ] ) [ 'filter' ] valid_filters , invalid_filters = parse_filters ( filter_query_params ) invalid_filters |= incomplete_filters ( valid_filters ) invalid_filters |= invalid_fts_filters ( valid_filters ) return valid_filters if invalid_filters . empty? halt ( 400 , { 'Content-Type' => 'application/json' } , render_json ( { :status => 400 , :msg => \"Bad Request\" , :detail => invalid_filters . map { | invalid_filter | if invalid_filter . is_a? ( Hash ) && invalid_filter [ :error ] invalid_filter [ :error ] else invalid_filter end } . map ( :to_s ) } ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stores the original dimensions of the image as a serialized Hash in to the model [CODESPLIT] def make model = attachment . instance file_path = file . path rescue nil style = options [ :style ] if file_path width , height = ` #{ file_path } ` . split ( / / ) ## Read dimensions ## Set original height and width attributes on model model . retina_dimensions = ( model . retina_dimensions || { } ) . deep_merge! ( attachment . name => { style => { :width => width . to_i / 2 , :height => height . to_i / 2 } } ) end file end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensures that the module will re - extend Parameters :: ClassMethods when included . [CODESPLIT] def included ( base ) base . extend ClassMethods if base . kind_of? ( Module ) # re-extend the ModuleMethods base . extend ModuleMethods end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensures that the module will initialize parameters when extended into an Object . [CODESPLIT] def extended ( object ) each_param do | param | object . params [ param . name ] = param . to_instance ( object ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the values of the class parameters . [CODESPLIT] def params = ( values ) values . each do | name , value | if has_param? ( name ) get_param ( name ) . value = case value when Parameters :: ClassParam , Parameters :: InstanceParam value . value else value end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a new parameters to the class . [CODESPLIT] def parameter ( name , options = { } ) name = name . to_sym # define the reader class method for the parameter meta_def ( name ) do get_param ( name ) . value end # define the writer class method for the parameter meta_def ( \"#{name}=\" ) do | value | get_param ( name ) . value = value end # define the ? method, to determine if the parameter is set meta_def ( \"#{name}?\" ) do ! ! get_param ( name ) . value end # define the reader instance methods for the parameter define_method ( name ) do get_param ( name ) . value end # define the writter instance methods for the parameter define_method ( \"#{name}=\" ) do | value | get_param ( name ) . value = value end # define the ? method, to determine if the parameter is set define_method ( \"#{name}?\" ) do ! ! get_param ( name ) . value end # create the new parameter new_param = Parameters :: ClassParam . new ( name , options [ :type ] , options [ :description ] , options [ :default ] ) # add the parameter to the class params list params [ name ] = new_param return new_param end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determines if a class parameter exists with the given name . [CODESPLIT] def has_param? ( name ) name = name . to_sym ancestors . each do | ancestor | if ancestor . included_modules . include? ( Parameters ) return true if ancestor . params . has_key? ( name ) end end return false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Searches for the class parameter with the matching name . [CODESPLIT] def get_param ( name ) name = name . to_sym ancestors . each do | ancestor | if ancestor . included_modules . include? ( Parameters ) if ancestor . params . has_key? ( name ) return ancestor . params [ name ] end end end raise ( Parameters :: ParamNotFound , \"parameter #{name.to_s.dump} was not found in class #{self}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets a class parameter . [CODESPLIT] def set_param ( name , value ) name = name . to_sym ancestors . each do | ancestor | if ancestor . included_modules . include? ( Parameters ) if ancestor . params . has_key? ( name ) return ancestor . params [ name ] . set ( value ) end end end raise ( Parameters :: ParamNotFound , \"parameter #{name.to_s.dump} was not found in class #{self}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates over the parameters of the class and it s ancestors . [CODESPLIT] def each_param ( & block ) ancestors . reverse_each do | ancestor | if ancestor . included_modules . include? ( Parameters ) ancestor . params . each_value ( block ) end end return self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Hace una conversión recursiva de tipo de todos los values según los tipos de las keys indicados en types [CODESPLIT] def convert object , types , convert_fn case object when Array then object . map { | e | convert e , types , convert_fn } when Hash then Hash [ object . map do | k , v | [ k , v . is_a? ( Hash ) || v . is_a? ( Array ) ? convert ( v , types , convert_fn ) : convert_fn [ types [ k ] ] . call ( v ) ] end ] else object end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updating / Deleting [CODESPLIT] def update_all ( attributes = { } ) # Update using an attribute hash, or you can pass a block # and update the attributes directly on the objects. if block_given? to_a . each { | record | yield record } else to_a . each { | record | record . attributes = attributes } end zobject_class . update ( to_a ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wraps a Field object and typecasts / builds item as an array of the given field . [CODESPLIT] def type_cast ( values ) # Force into an array and run type_cast on each element. [ values ] . flatten . compact . map { | value | __getobj__ . type_cast ( value ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new Transaction [CODESPLIT] def link ( * things ) unless none? raise \"Illegal state for link: #{state}\" end things . each do | thing | case thing when DataMapper :: Adapters :: AbstractAdapter @adapters [ thing ] = :none when DataMapper :: Repository link ( thing . adapter ) when DataMapper :: Model link ( thing . repositories ) when DataMapper :: Resource link ( thing . model ) when Array link ( thing ) else raise \"Unknown argument to #{self.class}#link: #{thing.inspect} (#{thing.class})\" end end if block_given? commit { | * block_args | yield ( block_args ) } else self end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Commit the transaction [CODESPLIT] def commit if block_given? unless none? raise \"Illegal state for commit with block: #{state}\" end begin self . begin rval = within { | * block_args | yield ( block_args ) } rescue Exception => exception if begin? rollback end raise exception ensure unless exception if begin? commit end return rval end end else unless begin? raise \"Illegal state for commit without block: #{state}\" end each_adapter ( :commit_adapter , [ :log_fatal_transaction_breakage ] ) each_adapter ( :close_adapter , [ :log_fatal_transaction_breakage ] ) self . state = :commit end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute a block within this Transaction . [CODESPLIT] def within unless block_given? raise 'No block provided' end unless begin? raise \"Illegal state for within: #{state}\" end adapters = @adapters adapters . each_key do | adapter | adapter . push_transaction ( self ) end begin yield self ensure adapters . each_key do | adapter | adapter . pop_transaction end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse next message in buffer [CODESPLIT] def next_message read_header if @state == :header read_payload_length if @state == :payload_length read_mask_key if @state == :mask read_payload if @state == :payload @state == :complete ? process_frame! : nil rescue StandardError => ex if @on_error @on_error . call ( ex . message ) else raise ex end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates the reports [CODESPLIT] def reporter ( query , options = { } , & block ) @report ||= QueryReport :: Report . new ( params , view_context , options ) @report . query = query @report . instance_eval block render_report ( options ) unless options [ :skip_rendering ] @report end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Renders a form field with label wrapped in an appropriate + <div > + with another + <div > + for errors if necessary . [CODESPLIT] def input_div ( field_name , label : nil , type : nil , values : nil , field : { } ) raise ArgumentError , ':values is only meaningful with type: :select' if values && type != :select @template . content_tag :div , class : classes_for ( field_name ) do [ label ( field_name , label ) , input_for ( field_name , type , field , values : values ) , errors_for ( field_name ) ] . compact . join ( \"\\n\" ) . html_safe end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Renders a + <span > + with errors if there are any for the specified field or returns + nil + if not . [CODESPLIT] def errors_for ( field_name ) error_messages = errors [ field_name ] if error_messages . present? @template . content_tag :span , class : :error do error_messages . join ( @template . tag :br ) . html_safe end else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Infers the type of field to render based on the field name . [CODESPLIT] def infer_type ( field_name ) case field_name when :email , :time_zone field_name when %r{ \\b \\b } :password else type_mappings = { text : :textarea } db_type = @object . column_for_attribute ( field_name ) . type case db_type when :text :textarea when :decimal , :integer , :float :numeric else db_type end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "prepend is important! otherwise dependent : : destroy on node< - > node_map relation is executed first and no records! All the answer nodes that follow from this node [CODESPLIT] def answers nm = self . survey . node_maps next_answer_nodes = lambda { | node , list | nm . select { | node_map | ! node_map . parent . nil? && node_map . parent . node == node && node_map . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) && ! node_map . marked_for_destruction? } . select { | i | ! list . include? ( i . node ) } . collect { | i | i . survey = self . survey i . node . survey = self . survey list << i . node next_answer_nodes . call ( i . node , list ) } . flatten . uniq list } next_answer_nodes . call ( self , [ ] ) . flatten . uniq end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Default behaviour is to recurse up the chain ( goal is to hit a question node ) [CODESPLIT] def validate_parent_instance_node ( instance_node , child_node ) ! self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | if node_map . parent node_map . parent . node . validate_parent_instance_node ( instance_node , self ) # Hit top node else true end } . include? ( false ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run all validations applied to this node [CODESPLIT] def validate_instance_node ( instance_node ) # Basically this cache is messed up? Why? TODO. # Reloading in the spec seems to fix this... but... this could be a booby trap for others #self.node_validations(true) # Check the validations on this node against the instance_node validations_passed = ! self . node_validations . collect { | node_validation | node_validation . validate_instance_node ( instance_node , self ) } . include? ( false ) # More complex.... # Recureses to the parent node to check # This is to validate Node::Question since they don't have instance_nodes directly to validate them parent_validations_passed = ! self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | if node_map . parent node_map . parent . node . validate_parent_instance_node ( instance_node , self ) # Hit top node else true end } . include? ( false ) validations_passed && parent_validations_passed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Whether there is a valid answer path from this node to the root node for the instance [CODESPLIT] def instance_node_path_to_root? ( instance_node ) instance_nodes = instance_node . instance . instance_nodes . select { | i | i . node == self } # if ::ActiveRecordSurvey::Node::Answer but no votes, not a valid path if self . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) && ( instance_nodes . length === 0 ) return false end # if ::ActiveRecordSurvey::Node::Question but no answers, so needs at least one vote directly on itself if self . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) && ( self . answers . length === 0 ) && ( instance_nodes . length === 0 ) return false end # Start at each node_map of this node # Find the parent node ma paths = self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | # There is another level to traverse if node_map . parent node_map . parent . node . instance_node_path_to_root? ( instance_node ) # This is the root node - we made it! else true end } # If recursion reports back to have at least one valid path to root paths . include? ( true ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build a link from this node to another node Building a link actually needs to throw off a whole new clone of all children nodes [CODESPLIT] def build_link ( to_node ) # build_link only accepts a to_node that inherits from Question if ! to_node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) raise ArgumentError . new \"to_node must inherit from ::ActiveRecordSurvey::Node::Question\" end if self . survey . nil? raise ArgumentError . new \"A survey is required before calling #build_link\" end from_node_maps = self . survey . node_maps . select { | i | i . node == self && ! i . marked_for_destruction? } # Answer has already got a question - throw error if from_node_maps . select { | i | i . children . length > 0 } . length > 0 raise RuntimeError . new \"This node has already been linked\" end # Because we need something to clone - filter this further below to_node_maps = self . survey . node_maps . select { | i | i . node == to_node && ! i . marked_for_destruction? } if to_node_maps . first . nil? to_node_maps << self . survey . node_maps . build ( :survey => self . survey , :node => to_node ) end # Ensure we can through each possible path of getting to this answer to_node_map = to_node_maps . first to_node_map . survey = self . survey # required due to voodoo - we want to use the same survey with the same object_id # We only want node maps that aren't linked somewhere to_node_maps = to_node_maps . select { | i | i . parent . nil? } while to_node_maps . length < from_node_maps . length do to_node_maps . push ( to_node_map . recursive_clone ) end # Link unused node_maps to the new parents from_node_maps . each_with_index { | from_node_map , index | from_node_map . children << to_node_maps [ index ] } # Ensure no infinite loops were created from_node_maps . each { | node_map | # There is a path from Q -> A that is a loop if node_map . has_infinite_loop? raise RuntimeError . new \"Infinite loop detected\" end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Before a node is destroyed will re - build the node_map links from parent to child if they exist [CODESPLIT] def before_destroy_rebuild_node_map # All the node_maps from this node self . survey . node_maps . select { | i | i . node == self } . each { | node_map | # Remap all of this nodes children to the parent node_map . children . each { | child | node_map . parent . children << child } } true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Accept integer float or empty values [CODESPLIT] def validate_instance_node ( instance_node ) # super - all validations on this node pass super && ( instance_node . value . to_s . empty? || ! instance_node . value . to_s . match ( / \\d \\. \\d / ) . nil? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Scale answers are considered answered if they have a value of greater than 0 [CODESPLIT] def is_answered_for_instance? ( instance ) if instance_node = self . instance_node_for_instance ( instance ) # Answered if not empty and > 0 ! instance_node . value . to_s . empty? && instance_node . value . to_i >= 0 else false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Text answers are considered answered if they have text entered [CODESPLIT] def is_answered_for_instance? ( instance ) if instance_node = self . instance_node_for_instance ( instance ) # Answered if has text instance_node . value . to_s . strip . length > 0 else false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Recursively creates a copy of this entire node_map [CODESPLIT] def recursive_clone node_map = self . survey . node_maps . build ( :survey => self . survey , :node => self . node ) self . survey . node_maps . select { | i | i . parent == self && ! i . marked_for_destruction? } . each { | child_node | child_node . survey = self . survey # required due to voodoo - we want to use the same survey with the same object_id node_map . children << child_node . recursive_clone } node_map end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets all the ancestor nodes until one is not an ancestor of klass [CODESPLIT] def ancestors_until_node_not_ancestor_of ( klass ) if ! self . parent || ! self . node . class . ancestors . include? ( klass ) return [ ] end [ self ] + self . parent . ancestors_until_node_not_ancestor_of ( klass ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets all the child nodes until one is not an ancestor of klass [CODESPLIT] def children_until_node_not_ancestor_of ( klass ) if ! self . node . class . ancestors . include? ( klass ) return [ ] end [ self ] + self . children . collect { | i | i . children_until_node_not_ancestor_of ( klass ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check to see whether there is an infinite loop from this node_map [CODESPLIT] def has_infinite_loop? ( path = [ ] ) self . survey . node_maps . select { | i | i . parent == self && ! i . marked_for_destruction? } . each { | i | # Detect infinite loop if path . include? ( self . node ) || i . has_infinite_loop? ( path . clone . push ( self . node ) ) return true end } path . include? ( self . node ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validate the instance_node value is greater than the minimum [CODESPLIT] def validate_instance_node ( instance_node , answer_node = nil ) is_valid = ( ! instance_node . value . to_s . empty? && instance_node . value . to_f >= self . value . to_f ) instance_node . errors [ :base ] << { :nodes => { answer_node . id => [ \"MINIMUM_VALUE\" ] } } if ! is_valid is_valid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validate the instance_node to ensure a minimum number of answers are made [CODESPLIT] def validate_instance_node ( instance_node , question_node = nil ) # Only makes sense for questions to have minimum answers if ! question_node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) return false end instance = instance_node . instance # Go through the node_map of this node total_answered = question_node . node_maps . collect { | question_node_map | # Get all children until a childs node isn't an answer question_node_map . children . collect { | i | i . children_until_node_not_ancestor_of ( :: ActiveRecordSurvey :: Node :: Answer ) } . flatten . collect { | i | i . node . is_answered_for_instance? ( instance ) } } . flatten . select { | i | i } . count is_valid = ( total_answered >= self . value . to_i ) instance_node . errors [ :base ] << { :nodes => { question_node . id => [ \"MINIMUM_ANSWER\" ] } } if ! is_valid is_valid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Answer nodes are valid if their questions are valid! Validate this node against an instance [CODESPLIT] def validate_node ( instance ) # Ensure each parent node to this node (the goal here is to hit a question node) is valid ! self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | node_map . parent . node . validate_node ( instance ) } . include? ( false ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the question that preceeds this answer [CODESPLIT] def question self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | if node_map . parent && node_map . parent . node # Question is not the next parent - recurse! if node_map . parent . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) node_map . parent . node . question else node_map . parent . node end # Root already else nil end } . first end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the question that follows this answer [CODESPLIT] def next_question self . survey . node_maps . select { | i | i . node == self && ! i . marked_for_destruction? } . each { | answer_node_map | answer_node_map . children . each { | child | if ! child . node . nil? && ! child . marked_for_destruction? if child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) return child . node elsif child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) return child . node . next_question end else return nil end } } return nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes the node_map from this answer to its next question [CODESPLIT] def remove_link # not linked to a question - nothing to remove! return true if ( question = self . next_question ) . nil? count = 0 to_remove = [ ] self . survey . node_maps . each { | node_map | if node_map . node == question if count > 0 to_remove . concat ( node_map . self_and_descendants ) else node_map . parent = nil node_map . move_to_root unless node_map . new_record? end count = count + 1 end if node_map . node == self node_map . children = [ ] end } self . survey . node_maps . each { | node_map | if to_remove . include? ( node_map ) node_map . parent = nil node_map . mark_for_destruction end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets index in sibling relationship [CODESPLIT] def sibling_index node_maps = self . survey . node_maps if node_map = node_maps . select { | i | i . node == self } . first parent = node_map . parent children = node_maps . select { | i | i . parent && i . parent . node === parent . node } children . each_with_index { | nm , i | if nm == node_map return i end } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Moves answer up relative to other answers [CODESPLIT] def move_up self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | begin node_map . move_left rescue end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Moves answer down relative to other answers [CODESPLIT] def move_down self . survey . node_maps . select { | i | i . node == self } . collect { | node_map | begin node_map . move_right rescue end } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "By default - answers build off the original question node [CODESPLIT] def remove_answer ( question_node ) #self.survey = question_node.survey # The node from answer from the parent question self . survey . node_maps . select { | i | ! i . marked_for_destruction? && i . node == self && i . parent && i . parent . node === question_node } . each { | answer_node_map | answer_node_map . send ( ( answer_node_map . new_record? ) ? :destroy : :mark_for_destruction ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "By default - answers build off the original question node [CODESPLIT] def build_answer ( question_node ) self . survey = question_node . survey answer_node_maps = self . survey . node_maps . select { | i | i . node == self && i . parent . nil? } . collect { | i | i . survey = self . survey i } question_node_maps = self . survey . node_maps . select { | i | i . node == question_node && ! i . marked_for_destruction? } # No node_maps exist yet from this question if question_node_maps . length === 0 # Build our first node-map question_node_maps << self . survey . node_maps . build ( :node => question_node , :survey => self . survey ) end # Each instance of this question needs the answer hung from it question_node_maps . each_with_index { | question_node_map , index | if answer_node_maps [ index ] new_node_map = answer_node_maps [ index ] else new_node_map = self . survey . node_maps . build ( :node => self , :survey => self . survey ) end question_node_map . children << new_node_map } true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Accept integer or empty values Must be within range of the number of ranking nodes [CODESPLIT] def validate_instance_node ( instance_node ) # super - all validations on this node pass super && ( instance_node . value . to_s . empty? || ! instance_node . value . to_s . match ( / \\d / ) . nil? ) && ( instance_node . value . to_s . empty? || instance_node . value . to_i >= 1 ) && instance_node . value . to_i <= self . max_rank end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the number of Rank nodes above this one [CODESPLIT] def num_above count = 0 self . node_maps . each { | i | # Parent is one of us as well - include it and check its parents if i . parent . node . class . ancestors . include? ( self . class ) count = count + 1 + i . parent . node . num_above end } count end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the number of Rank nodes below this one [CODESPLIT] def num_below count = 0 self . node_maps . each { | node_map | node_map . children . each { | child | # Child is one of us as well - include it and check its children if child . node . class . ancestors . include? ( self . class ) count = count + 1 + child . node . num_below end } } count end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validate the instance_node value [CODESPLIT] def validate_instance_node ( instance_node , answer_node = nil ) is_valid = ( self . value . to_i >= instance_node . value . to_s . length . to_i ) instance_node . errors [ :base ] << { :nodes => { answer_node . id => [ \"MAXIMUM_LENGTH\" ] } } if ! is_valid is_valid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Builds first question [CODESPLIT] def build_first_question ( question_node ) if ! question_node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) raise ArgumentError . new \"must inherit from ::ActiveRecordSurvey::Node::Question\" end question_node_maps = self . node_maps . select { | i | i . node == question_node && ! i . marked_for_destruction? } # No node_maps exist yet from this question if question_node_maps . length === 0 # Build our first node-map question_node_maps << self . node_maps . build ( :node => question_node , :survey => self ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "All the connective edges [CODESPLIT] def edges self . node_maps . select { | i | ! i . marked_for_destruction? } . select { | i | i . node && i . parent } . collect { | i | { :source => i . parent . node . id , :target => i . node . id , } } . uniq end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stop validating at the Question node [CODESPLIT] def validate_parent_instance_node ( instance_node , child_node ) ! self . node_validations . collect { | node_validation | node_validation . validate_instance_node ( instance_node , self ) } . include? ( false ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Updates the answers of this question to a different type [CODESPLIT] def update_question_type ( klass ) if self . next_questions . length > 0 raise RuntimeError . new \"No questions can follow when changing the question type\" end nm = self . survey . node_maps answers = self . answers . collect { | answer | nm . select { | i | i . node == answer } } . flatten . uniq . collect { | answer_node_map | node = answer_node_map . node answer_node_map . send ( ( answer_node_map . new_record? ) ? :destroy : :mark_for_destruction ) node } . collect { | answer | answer . type = klass . to_s answer = answer . becomes ( klass ) answer . save if ! answer . new_record? answer } . uniq answers . each { | answer | answer . survey = self . survey self . build_answer ( answer ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes an answer [CODESPLIT] def remove_answer ( answer_node ) # A survey must either be passed or already present in self.node_maps if self . survey . nil? raise ArgumentError . new \"A survey must be passed if ActiveRecordSurvey::Node::Question is not yet added to a survey\" end if ! answer_node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) raise ArgumentError . new \"::ActiveRecordSurvey::Node::Answer not passed\" end # Cannot mix answer types # Check if not match existing - throw error if ! self . answers . include? ( answer_node ) raise ArgumentError . new \"Answer not linked to question\" end answer_node . send ( :remove_answer , self ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build an answer off this node [CODESPLIT] def build_answer ( answer_node ) # A survey must either be passed or already present in self.node_maps if self . survey . nil? raise ArgumentError . new \"A survey must be passed if ActiveRecordSurvey::Node::Question is not yet added to a survey\" end # Cannot mix answer types # Check if not match existing - throw error if ! self . answers . select { | answer | answer . class != answer_node . class } . empty? raise ArgumentError . new \"Cannot mix answer types on question\" end # Answers actually define how they're built off the parent node if answer_node . send ( :build_answer , self ) # If any questions existed directly following this question, insert after this answer self . survey . node_maps . select { | i | i . node == answer_node && ! i . marked_for_destruction? } . each { | answer_node_map | self . survey . node_maps . select { | j | # Same parent # Is a question ! j . marked_for_destruction? && j . parent == answer_node_map . parent && j . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) } . each { | j | answer_node_map . survey = self . survey j . survey = self . survey answer_node_map . children << j } } true end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes the node_map link from this question all of its next questions [CODESPLIT] def remove_link return true if ( questions = self . next_questions ) . length === 0 # Remove the link to any direct questions self . survey . node_maps . select { | i | i . node == self } . each { | node_map | self . survey . node_maps . select { | j | node_map . children . include? ( j ) } . each { | child | if child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) child . parent = nil child . send ( ( child . new_record? ) ? :destroy : :mark_for_destruction ) end } } # remove link any answeres that have questions self . answers . collect { | i | i . remove_link } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the questions that follows this question ( either directly or via its answers ) [CODESPLIT] def next_questions list = [ ] if question_node_map = self . survey . node_maps . select { | i | i . node == self && ! i . marked_for_destruction? } . first question_node_map . children . each { | child | if ! child . node . nil? && ! child . marked_for_destruction? if child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Question ) list << child . node elsif child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) list << child . node . next_question end end } end list . compact . uniq end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Before a node is destroyed will re - build the node_map links from parent to child if they exist If a question is being destroyed and it has answers - don t link its answers - only parent questions that follow it [CODESPLIT] def before_destroy_rebuild_node_map self . survey . node_maps . select { | i | i . node == self } . each { | node_map | # Remap all of this nodes children to the parent node_map . children . each { | child | if ! child . node . class . ancestors . include? ( :: ActiveRecordSurvey :: Node :: Answer ) node_map . parent . children << child end } } true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns and outputs a table for the given active record collection [CODESPLIT] def table_for ( collection , * args , & block ) block = Tabletastic . default_table_block unless block_given? klass = default_class_for ( collection ) options = args . extract_options! initialize_html_options ( options , klass ) result = capture { block . call ( TableBuilder . new ( collection , klass , self ) ) } content_tag ( :table , result , options [ :html ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds the class representing the objects within the collection [CODESPLIT] def default_class_for ( collection ) if collection . respond_to? ( :klass ) # ActiveRecord::Relation collection . klass elsif ! collection . empty? collection . first . class end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@example Adding a new SceneEvent to the Dictionary [CODESPLIT] def add ( params = { } ) target = params [ :target ] event = EventFactory . new params [ :type ] , params [ :args ] , params [ :block ] events [ target ] = events_for_target ( target ) . push event end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return all the events for all the specified targets . [CODESPLIT] def events_for_targets ( * list ) found_events = Array ( list ) . flatten . compact . map { | s | events_for_target ( s ) } . flatten . compact found_events end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The writer for this view . If the view has already been parsed then use [CODESPLIT] def writer @writer ||= begin writer_matching_existing_parser = supported_writers . find { | writer | writer . format == format } writer_matching_existing_parser || default_writer end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A TMX object currently has an array of points in a format list of strings . This will convert the points into list of CP :: Vec2 objects which can be used to create the proper CP :: Shape :: Poly for the Object . [CODESPLIT] def poly_vec2s points . map do | point | x , y = point . split ( \",\" ) . map { | p | p . to_i } CP :: Vec2 . new ( x , y ) end . reverse end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Define an animation from within another animation block an event block or a method . [CODESPLIT] def animate ( actor_or_actor_name , options , & block ) options [ :actor ] = actor ( actor_or_actor_name ) options [ :context ] = self animation_group = SceneAnimation . build options , block enqueue animation_group end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register for mouse movements events . These events are fired each update providing an event which contains the current position of the mouse . [CODESPLIT] def on_mouse_movement ( * args , & block ) options = ( args . last . is_a? ( Hash ) ? args . pop : { } ) @mouse_movement_actions << ( block || lambda { | instance | send ( options [ :do ] ) } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register for a custom notification event . These events are fired when another object within the game posts a notification with matching criteria . If there has indeed been a match then the stored action block will be fired . [CODESPLIT] def notification ( param , & block ) custom_notifications [ param . to_sym ] = custom_notifications [ param . to_sym ] + [ block ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fire the events mapped to the held buttons within the context of the specified target . This method is differently formatted because held buttons are not events but polling to see if the button is still being held . [CODESPLIT] def fire_events_for_held_buttons held_actions . each do | key , action | execute_block_for_target ( action ) if window and window . button_down? ( key ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fire all events mapped to the matching notification . [CODESPLIT] def fire_events_for_notification ( event , sender ) notification_actions = custom_notifications [ event ] notification_actions . each do | action | _fire_event_for_notification ( event , sender , action ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fire a single event based on the matched notification . [CODESPLIT] def _fire_event_for_notification ( event , sender , action ) if action . arity == 2 target . instance_exec ( sender , event , action ) elsif action . arity == 1 target . instance_exec ( sender , action ) else target . instance_eval ( action ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a model and all it s subclasses to the list of available models . [CODESPLIT] def add ( model ) all_models_for ( model ) . each do | model | models_hash [ model . to_s ] = model . to_s name_with_slashes = model . model_name models_hash [ name_with_slashes ] = model . to_s name_with_colons = name_with_slashes . gsub ( '/' , '::' ) models_hash [ name_with_colons ] = model . to_s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Additional initializion is required to calculate the attributes that are going to be animated and to determine each of their deltas . [CODESPLIT] def after_initialize to . each do | attribute , final | start = actor . send ( attribute ) animations . push build_animation_step ( attribute , start , final ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fire notification events within the current game state [CODESPLIT] def fire_events_for_notification ( event , sender ) current_state . each { | cs | cs . fire_events_for_notification ( event , sender ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "An an event relay to the current game state [CODESPLIT] def add_events_for_target ( target , events ) relay = EventRelay . new ( target , window ) events . each do | target_event | relay . send target_event . event , target_event . buttons , target_event . block end current_state . push relay end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creation through controls is usually done with an instance_eval of a block and this allows for a flexible interface . [CODESPLIT] def method_missing ( name , * params , & block ) options = params . find { | param | param . is_a? Hash } define_control ( name , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a window and starts the game with the game parameters . [CODESPLIT] def start! @window = Window . new width , height , fullscreen? window . caption = name window . scene = Scenes . generate ( first_scene ) window . show end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "When the scene is shown set up the starting color for the rectangle and queue the animation to transition the color to the final color . [CODESPLIT] def show rectangle . color = starting_color color = final_color animate :rectangle , to : { red : color . red , green : color . green , blue : color . blue , alpha : color . alpha } , interval : interval do transition_to next_scene end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "builds up the fields that the table will include returns table head and body with all data [CODESPLIT] def data ( * args , & block ) # :yields: tablebody options = args . extract_options! if block_given? yield self else @table_fields = args . empty? ? orm_fields : args . collect { | f | TableField . new ( f . to_sym ) } end action_cells ( options [ :actions ] , options [ :action_prefix ] ) [ \"\\n\" , head , \"\\n\" , body , \"\\n\" ] . join ( \"\" ) . html_safe end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "individually specify a column which will build up the header and method or block to call on each resource in the array [CODESPLIT] def cell ( * args , & proc ) options = args . extract_options! options . merge! ( :klass => klass ) args << options @table_fields << TableField . new ( args , proc ) # Since this will likely be called with <%= %> (aka 'concat'), explicitly return an  # empty string; this suppresses unwanted output return \"\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Used internally to build up cells for common CRUD actions [CODESPLIT] def action_cells ( actions , prefix = nil ) return if actions . blank? actions = [ actions ] if ! actions . respond_to? ( :each ) actions = [ :show , :edit , :destroy ] if actions == [ :all ] actions . each do | action | action_link ( action . to_sym , prefix ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Dynamically builds links for the action [CODESPLIT] def action_link ( action , prefix ) html_class = \"actions #{action.to_s}_link\" block = lambda do | resource | compound_resource = [ prefix , resource ] . compact compound_resource . flatten! if prefix . kind_of? ( Array ) case action when :show @template . link_to ( link_title ( action ) , compound_resource ) when :destroy @template . link_to ( link_title ( action ) , compound_resource , :method => :delete , :data => { :confirm => confirmation_message } ) else # edit, other resource GET actions @template . link_to ( link_title ( action ) , @template . polymorphic_path ( compound_resource , :action => action ) ) end end self . cell ( action , :heading => \"\" , :cell_html => { :class => html_class } , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a scene to the hash of scenes with the scene name of the scene as the key to retrieving this scene . [CODESPLIT] def add ( scene ) all_scenes_for ( scene ) . each { | scene | scenes_hash [ scene . scene_name ] = scene . to_s } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Apply all the post filtering to the specified scene with the given options [CODESPLIT] def apply_post_filters ( new_scene , options ) post_filters . inject ( new_scene ) { | scene , post | post . filter ( scene , options ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a hash that will return a setup missing scene by default . [CODESPLIT] def hash_with_missing_scene_default hash = HashWithIndifferentAccess . new do | hash , key | missing_scene = hash [ :missing_scene ] . constantize missing_scene . missing_scene = key . to_sym missing_scene end hash [ :missing_scene ] = \"Metro::MissingScene\" hash end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns all subclassed scenes of the scene or scenes provided . This method is meant to be called recursively to generate the entire list of all the scenes . [CODESPLIT] def all_scenes_for ( scenes ) Array ( scenes ) . map do | scene_class_name | scene = scene_class_name . constantize [ scene ] + all_scenes_for ( scene . scenes ) end . flatten . compact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "When an actor is defined through the class method draw a getter and setter method is defined . However it is a better interface internally not to rely heavily on send and have this small amount of obfuscation in the event that this needs to change . [CODESPLIT] def actor ( actor_or_actor_name ) if actor_or_actor_name . is_a? String or actor_or_actor_name . is_a? Symbol send ( actor_or_actor_name ) else actor_or_actor_name end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Post a custom notification event . This will trigger an event for all the objects that are registered for notification with the current state . [CODESPLIT] def notification ( event , sender = nil ) sender = sender || UnknownSender state . fire_events_for_notification ( event , sender ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform an operation after the specified interval . [CODESPLIT] def after ( ticks , & block ) tick = OnUpdateOperation . new interval : ticks , context : self tick . on_complete ( block ) enqueue tick end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Setups up the Actors for the Scene based on the ModelFactories that have been defined . [CODESPLIT] def add_actors_to_scene self . class . actors . each do | scene_actor | actor_instance = scene_actor . create actor_instance . scene = self send \"#{scene_actor.name}=\" , actor_instance end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Setting the window places the scene within in the specified window . Which will cause a number of variables and settings to be set up . The { #show } method is called after the window has been set . [CODESPLIT] def window = ( window ) @window = window state . window = window state . clear register_events! register_actors! register_animations! register_after_intervals! show end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register all the animations that were defined for this scene . [CODESPLIT] def register_animations! self . class . animations . each do | animation | animate animation . actor , animation . options , animation . on_complete_block end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Registering an actor involves setting up the actor within the window adding them to the list of things that need to be drawn and then registering any eventst that they might have . [CODESPLIT] def register_actor ( actor_factory ) registering_actor = actor ( actor_factory . name ) registering_actor . window = window registering_actor . show drawers . push ( registering_actor ) updaters . push ( registering_actor ) register_events_for_target ( registering_actor , registering_actor . class . events ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The base_update method is called by the Game Window . This is to allow for any special update needs to be handled before calling the traditional update method defined in the subclassed Scene . [CODESPLIT] def base_update updaters . each { | updater | updater . update } update updaters . reject! { | updater | updater . update_completed? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The base_draw method is called by the Game Window . This is to allow for any special drawing needs to be handled before calling the traditional draw method defined in the subclassed Scene . [CODESPLIT] def base_draw drawers . each { | drawer | drawer . draw } draw drawers . reject! { | drawer | drawer . draw_completed? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "transition_to performs the work of transitioning this scene to another scene . [CODESPLIT] def transition_to ( scene_or_scene_name , options = { } ) new_scene = Scenes . generate ( scene_or_scene_name , options ) _prepare_transition ( new_scene ) window . scene = new_scene end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Before a scene is transitioned away from to a new scene this private method is here to allow for any housekeeping or other work that needs to be done before calling the subclasses implementation of prepare_transition . [CODESPLIT] def _prepare_transition ( new_scene ) log . debug \"Preparing to transition from scene #{self} to #{new_scene}\" new_scene . class . actors . find_all { | actor_factory | actor_factory . load_from_previous_scene? } . each do | actor_factory | new_actor = new_scene . actor ( actor_factory . name ) current_actor = actor ( actor_factory . name ) new_actor . _load current_actor . _save end prepare_transition_to ( new_scene ) new_scene . prepare_transition_from ( self ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A Scene represented as a hash currently only contains the drawers [CODESPLIT] def to_hash drawn = drawers . find_all { | draw | draw . saveable_to_view } . inject ( { } ) do | hash , drawer | drawer_hash = drawer . to_hash hash . merge drawer_hash end drawn end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A helper method that allows the current model to generate another model . This is useful as it allows for the current model to pass window and scene state to the created model . [CODESPLIT] def create ( model_name , options = { } ) # @TODO: this is another path that parallels the ModelFactory model_class = Metro :: Models . find ( model_name ) mc = model_class . new options mc . scene = scene mc . window = window mc end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create an instance of a model . [CODESPLIT] def _load ( options = { } ) # Clean up and symbolize all the keys then merge that with the existing properties options . keys . each do | key | property_name = key . to_s . underscore . to_sym if respond_to? \"#{property_name}=\" send ( \"#{property_name}=\" , options . delete ( key ) ) else options [ property_name ] = options . delete ( key ) end end properties . merge! options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a list of activity measures for the specified user [CODESPLIT] def activities ( user_id , options = { } ) perform_request ( :get , '/v2/measure' , WithingsSDK :: Activity , 'activities' , { action : 'getactivity' , userid : user_id } . merge ( options ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a list of body measurements taken by Withings devices [CODESPLIT] def body_measurements ( user_id , options = { } ) perform_request ( :get , '/measure' , WithingsSDK :: MeasurementGroup , 'measuregrps' , { action : 'getmeas' , userid : user_id } . merge ( options ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a list of weight body measurements [CODESPLIT] def weight ( user_id , options = { } ) groups = body_measurements ( user_id , options ) groups . map do | group | group . measures . select { | m | m . is_a? WithingsSDK :: Measure :: Weight } . map do | m | WithingsSDK :: Measure :: Weight . new ( m . attrs . merge ( 'weighed_at' => group . date ) ) end end . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get details about a user s sleep [CODESPLIT] def sleep_series ( user_id , options = { } ) perform_request ( :get , '/v2/sleep' , WithingsSDK :: SleepSeries , 'series' , { action : 'get' , userid : user_id } . merge ( options ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helper function that handles all API requests [CODESPLIT] def perform_request ( http_method , path , klass , key , options = { } ) if @consumer_key . nil? || @consumer_secret . nil? raise WithingsSDK :: Error :: ClientConfigurationError , \"Missing consumer_key or consumer_secret\" end options = WithingsSDK :: Utils . normalize_date_params ( options ) request = WithingsSDK :: HTTP :: Request . new ( @access_token , { 'User-Agent' => user_agent } ) response = request . send ( http_method , path , options ) if key . nil? klass . new ( response ) elsif response . has_key? key response [ key ] . collect do | element | klass . new ( element ) end else [ klass . new ( response ) ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Search resources like a movie a person a collection and so on . [CODESPLIT] def search ( query , options = { } ) options . merge! ( query : query ) res = get ( \"/search/#{resource}\" , query : options ) if res . success? res [ 'results' ] . map { | attributes | new ( attributes ) } else bad_response ( res ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Sets the attributes to the object . [CODESPLIT] def set_attributes ( attributes ) attributes . each do | key , value | if candidate_to_object? ( value ) next unless TMDb . const_defined? ( key . classify ) value = build_objects ( key , value ) end self . instance_variable_set ( \"@#{key}\" , value ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Verifies if the value is an array of hashs . [CODESPLIT] def candidate_to_object? ( value ) value . is_a? ( Array ) && ! value . empty? && value . all? { | h | h . is_a? ( Hash ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Builds objects for the nested resources from API . [CODESPLIT] def build_objects ( key , values ) klass = TMDb . const_get ( key . classify ) values . map do | attr | klass . new ( attr ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Exchange operations [CODESPLIT] def exchange_declare ( name , type , ** opts ) send_request :exchange_declare , { exchange : name , type : type , passive : opts . fetch ( :passive , false ) , durable : opts . fetch ( :durable , false ) , auto_delete : opts . fetch ( :auto_delete , false ) , internal : opts . fetch ( :internal , false ) , arguments : opts . fetch ( :arguments , { } ) } fetch_response :exchange_declare_ok end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Queue operations [CODESPLIT] def queue_declare ( name , ** opts ) send_request :queue_declare , { queue : name , passive : opts . fetch ( :passive , false ) , durable : opts . fetch ( :durable , false ) , exclusive : opts . fetch ( :exclusive , false ) , auto_delete : opts . fetch ( :auto_delete , false ) , arguments : opts . fetch ( :arguments , { } ) } fetch_response :queue_declare_ok end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Consumer operations [CODESPLIT] def basic_qos ( ** opts ) send_request :basic_qos , { prefetch_count : opts . fetch ( :prefetch_count , 0 ) , prefetch_size : opts . fetch ( :prefetch_size , 0 ) , global : opts . fetch ( :global , false ) } fetch_response :basic_qos_ok end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Message operations [CODESPLIT] def basic_get ( queue , ** opts ) send_request :basic_get , { queue : queue , no_ack : opts . fetch ( :no_ack , false ) } fetch_response [ :basic_get_ok , :basic_get_empty ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Changes the file content_type using the ruby - filemagic gem [CODESPLIT] def set_magic_content_type ( override = false ) if override || file . content_type . blank? || generic_content_type? ( file . content_type ) new_content_type = :: FileMagic . new ( :: FileMagic :: MAGIC_MIME ) . file ( file . path ) . split ( ';' ) . first if file . respond_to? ( :content_type= ) file . content_type = new_content_type else file . instance_variable_set ( :@content_type , new_content_type ) end end rescue :: Exception => e raise CarrierWave :: ProcessingError , I18n . translate ( :\" \" , e : e , default : 'Failed to process file with FileMagic, Original Error: %{e}' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Send a request on the given channel with the given type and properties . [CODESPLIT] def send_request ( channel_id , method , properties = { } ) Util . error_check :\" \" , @conn . send_method ( Integer ( channel_id ) , method . to_sym , properties ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wait for a specific response on the given channel of the given type and return the event data for the response when it is received . Any other events received will be processed or stored internally . [CODESPLIT] def fetch_response ( channel_id , method , timeout : protocol_timeout ) methods = Array ( method ) . map ( :to_sym ) timeout = Float ( timeout ) if timeout fetch_response_internal ( Integer ( channel_id ) , methods , timeout ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Register a handler for events on the given channel of the given type . Only one handler for each event type may be registered at a time . If no callable or block is given the handler will be cleared . [CODESPLIT] def on_event ( channel_id , method , callable = nil , & block ) handler = block || callable raise ArgumentError , \"expected block or callable as the event handler\" unless handler . respond_to? ( :call ) @event_handlers [ Integer ( channel_id ) ] [ method . to_sym ] = handler handler end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fetch and handle events in a loop that blocks the calling thread . The loop will continue until the { #break! } method is called from within an event handler or until the given timeout duration has elapsed . [CODESPLIT] def run_loop! ( timeout : protocol_timeout , & block ) timeout = Float ( timeout ) if timeout @breaking = false fetch_events ( timeout , block ) nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Open a new channel of communication and return a new { Channel } object with convenience methods for communicating on that channel . The channel will be automatically released if the { Channel } instance is garbage collected or if the { Client } connection is { #close } d . [CODESPLIT] def channel ( id = nil ) id = allocate_channel ( id ) finalizer = Proc . new { release_channel ( id ) } Channel . new ( self , @conn , id , finalizer ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Download the data from the remote server [CODESPLIT] def download_source Log . debug { \"         Reading #{@source.url.green}\" } zip = Tempfile . new ( 'gtfs' ) zip . binmode zip << open ( @source . url ) . read zip . rewind extract_to_tempfiles ( zip ) Log . debug { \"Finished reading #{@source.url.green}\" } rescue StandardException => e Log . error ( e . message ) raise e ensure zip . try ( :close ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse the filenames in the feed and check which required and optional files are present . [CODESPLIT] def check_files @found_files = [ ] check_required_files check_optional_files # Add feed files of zip to the list of files to be processed @source . feed_definition . files . each do | req | @found_files << req if filenames . include? ( req . filename ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check that every file has its required columns [CODESPLIT] def check_columns @found_files . each do | file | @temp_files [ file . filename ] . open do | data | FileReader . new ( data , file , validate : true ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check for the given list of expected filenames in the zip file [CODESPLIT] def check_missing_files ( expected , found_color , missing_color ) check = '✔'.c o lorize(f o und_color)  cross = '✘'.c o lorize(m i ssing_color)  expected . map do | req | filename = req . filename if filenames . include? ( filename ) Log . info { \"#{filename.rjust(filename_width)} [#{check}]\" } nil else Log . info { \"#{filename.rjust(filename_width)} [#{cross}]\" } filename end end . compact end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a HEAD request against the source s URL looking for a unique identifier for the remote data set . It will choose a header from the result in the given order of preference : - ETag - Last - Modified - Content - Length ( may result in different data sets being considered the same if they happen to have the same size ) - The current date / time ( this will always result in a fresh download ) [CODESPLIT] def fetch_data_set_identifier if @source . url =~ / \\A #{ URI :: DEFAULT_PARSER . make_regexp } \\z / uri = URI ( @source . url ) Net :: HTTP . start ( uri . host ) do | http | head_request = http . request_head ( uri . path ) if head_request . key? ( 'etag' ) head_request [ 'etag' ] else Log . warn ( \"No ETag supplied with: #{uri.path}\" ) fetch_http_fallback_identifier ( head_request ) end end else # it's not a url, it may be a file => last modified begin File . mtime ( @source . url ) rescue StandardError => e Log . error ( e ) raise e end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find a next best ID when the HEAD request does not return an ETag header . [CODESPLIT] def fetch_http_fallback_identifier ( head_request ) if head_request . key? ( 'last-modified' ) head_request [ 'last-modified' ] elsif head_request . key? ( 'content-length' ) head_request [ 'content-length' ] else Time . now . to_s end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates simple configuration parameters which may be set by the user [CODESPLIT] def parameter ( * names ) names . each do | name | define_singleton_method ( name ) do | * values | if ( value = values . first ) instance_variable_set ( \"@#{name}\" , value ) else instance_variable_get ( \"@#{name}\" ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check the list of headers in the file against the expected columns in the definition [CODESPLIT] def find_columns ( validate ) @found_columns = [ ] prefix = \"#{filename.yellow}:\" required = @definition . required_columns unless required . empty? Log . info { \"#{prefix} #{'required columns'.magenta}\" } if validate missing = check_columns ( validate , prefix , required , :green , :red ) raise RequiredColumnsMissing , missing if validate && missing . present? end optional = @definition . optional_columns unless optional . empty? Log . info { \"#{prefix} #{'optional columns'.cyan}\" } if validate check_columns ( validate , prefix , optional , :cyan , :light_yellow ) end cols = @definition . columns . collect ( :name ) headers = @csv_headers . select { | h | cols . include? ( h ) } @col_names ||= @found_columns . map ( :name ) :: Hash [ headers . inject ( [ ] ) { | list , c | list << c << @definition [ c ] } ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Proxies model mapping to the proper platform mapper [CODESPLIT] def map ( models , options ) models = models . values case options [ :platform ] . downcase when \"objc\" , \"obj-c\" , \"objective-c\" Nidyx :: ObjCMapper . map ( models , options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generates a Model and adds it to the models array . [CODESPLIT] def generate ( path , name ) object = get_object ( path ) type = object [ TYPE_KEY ] if type == OBJECT_TYPE generate_object ( path , name ) elsif type == ARRAY_TYPE generate_top_level_array ( path ) elsif type . is_a? ( Array ) if type . include? ( OBJECT_TYPE ) raise UnsupportedSchemaError if type . include? ( ARRAY_TYPE ) generate_object ( path , name ) elsif type . include? ( ARRAY_TYPE ) generate_top_leve_array ( path ) else raise UnsupportedSchemaError ; end else raise UnsupportedSchemaError ; end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a path which could be at any part of a reference chain resolve the immediate schema object . This means : [CODESPLIT] def resolve_reference ( path , parent = nil ) obj = get_object ( path ) ref = obj [ REF_KEY ] # TODO: merge parent and obj into obj (destructive) # If we find an immediate reference, chase it and pass the immediate # object as a parent. return resolve_reference_string ( ref ) if ref # If we are dealing with an object, encode it's class name into the # schema and generate it's model if necessary. if include_type? ( obj , OBJECT_TYPE ) && obj [ PROPERTIES_KEY ] obj [ DERIVED_NAME ] = class_name_from_path ( @class_prefix , path , @schema ) generate ( path , obj [ DERIVED_NAME ] ) unless @models . has_key? ( obj [ DERIVED_NAME ] ) end obj end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Resolves any references buied in the items property of an array definition . Returns a list of collection types in the array . [CODESPLIT] def resolve_array_refs ( obj ) items = obj [ ITEMS_KEY ] case items when Array return resolve_items_array ( items ) when Hash # handle a nested any of key any_of = items [ ANY_OF_KEY ] return resolve_items_array ( any_of ) if any_of . is_a? ( Array ) resolve_reference_string ( items [ REF_KEY ] ) return [ class_name_from_ref ( items [ REF_KEY ] ) ] . compact else return [ ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The Nidyx model generator . Called by the Nidyx CLI . Parses the input schema creates models and writes them to the output directory . [CODESPLIT] def run ( schema_path , options ) schema = Nidyx :: Reader . read ( schema_path ) raw_models = Nidyx :: Parser . parse ( schema , options ) models = Nidyx :: Mapper . map ( raw_models , options ) Nidyx :: Output . write ( models , options [ :output_directory ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Reads JSON from a file [CODESPLIT] def read ( path ) schema = nil begin # TODO: validate this is legitimate JSON Schema schema = JSON . parse ( IO . read ( path ) ) raise EmptySchemaError if empty_schema? ( schema ) rescue JSON :: JSONError => e puts \"Encountered an error reading JSON from #{path}\" puts e . message exit 1 rescue EmptySchemaError puts \"Schema read from #{path} is empty\" exit 1 rescue StandardError => e puts e . message exit 1 end schema end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Settings in config / environments / * take precedence over those specified here . Application configuration should go into files in config / initializers -- all . rb files in that directory are automatically loaded . Set Time . zone default to the specified zone and make Active Record auto - convert to this zone . Run rake - D time for a list of tasks for finding time zone names . Default is UTC . config . time_zone = Central Time ( US & Canada ) The default locale is : en and all translations from config / locales / * . rb yml are auto loaded . config . i18n . load_path + = Dir [ Rails . root . join ( my locales * . { rb yml } ) . to_s ] config . i18n . default_locale = : de [CODESPLIT] def load_console ( app = self ) super project_specific_irbrc = File . join ( Rails . root , \".irbrc\" ) if File . exists? ( project_specific_irbrc ) puts \"Loading project specific .irbrc ...\" load ( project_specific_irbrc ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "used in wechat pay api [CODESPLIT] def sign_package params params_str = create_sign_str params if params_str =~ / / key = Wxpay . app_api_key else key = Wxpay . api_key end Digest :: MD5 . hexdigest ( params_str + \"&key=#{key}\" ) . upcase end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if a status has been processed a Status has been processed when : The current status is superior or equal to the given status and the migration direction is UP The current status is inferior or equal to the given status and the migration direction is DOWN [CODESPLIT] def status_processed? ( migration_direction , status_to_process ) ( migration_direction == Migration :: UP && current_status >= status_to_process ) || ( migration_direction == Migration :: DOWN && current_status <= status_to_process ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------------------------- [CODESPLIT] def get_value ( key ) value = execute_command ( \"config #{@location} --null --get #{key}\" ) raise 'failure running command' if $? . exitstatus != 0 value . slice! ( 0 , value . length - 1 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "オーバーライドして : http_version と : message をenvに入れておく [CODESPLIT] def perform_request ( http , env ) http_response = super env [ :http_version ] = http_response . http_version env [ :message ] = http_response . message http_response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates and shows a UIAlertView . The first two parameters are required ( title and message ) . It returns an rmq object . [CODESPLIT] def alert ( title , message , cancel_button = 'OK' , other_buttons = [ ] , delegate = nil , view_style = UIAlertViewStyleDefault ) # TODO UIAlertView is deprecated in iOS 8. Should use UIAlertController for the future. alert_view = UIAlertView . alloc . initWithTitle ( title , message : message , delegate : delegate , cancelButtonTitle : cancel_button , otherButtonTitles : nil ) Array ( other_buttons ) . each { | button | alert_view . addButtonWithTitle ( button ) } alert_view . alertViewStyle = view_style alert_view . show rmq ( alert_view ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Recursive implementation of each_resource_file for each folder in the configuration . [CODESPLIT] def _each_resource_file ( config ) folder = config . folder folder . glob ( \"**/*.yml\" ) . select ( to_filter_proc ( config . file_filter ) ) . each do | file | yield file , folder end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Yields each resource in the current scope in turn . [CODESPLIT] def each_resource ( & bl ) return enum_for ( :each_resource ) unless block_given? each_resource_file do | file , folder | yield Webspicy . resource ( file . load , file , self ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert an instantiated URL found in a webservice definition to a real URL using the configuration host . [CODESPLIT] def to_real_url ( url , test_case = nil , & bl ) case config . host when Proc config . host . call ( url , test_case ) when String url =~ / / ? url : \"#{config.host}#{url}\" else return url if url =~ / / return yield ( url ) if block_given? raise \"Unable to resolve `#{url}` : no host resolver provided\\nSee `Configuration#host=\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a proc that implements file_filter strategy according to the type of filter installed [CODESPLIT] def to_filter_proc ( filter ) case ff = filter when NilClass then -> ( f ) { true } when Proc then ff when Regexp then -> ( f ) { ff =~ f . to_s } else -> ( f ) { ff === f } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a folder to the list of folders where test case definitions are to be found . [CODESPLIT] def folder ( folder = nil , & bl ) if folder . nil? @folder else folder = folder . is_a? ( String ) ? @folder / folder : Path ( folder ) raise \"Folder `#{folder}` does not exists\" unless folder . exists? && folder . directory? raise \"Folder must be a descendant\" unless folder . inside? ( @folder ) child = dup do | c | c . parent = self c . folder = folder end yield ( child ) if block_given? @children << child child end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the Data system to use for parsing schemas [CODESPLIT] def data_system schema = self . folder / \"schema.fio\" if schema . file? Finitio :: DEFAULT_SYSTEM . parse ( schema . read ) elsif not ( self . parent . nil? ) self . parent . data_system else Finitio :: DEFAULT_SYSTEM end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------------------------- ------------------------------------------------------------------------- [CODESPLIT] def untracked_files? # execute_command('status --porcelain | grep ??') # $?.exitstatus == 0 result = execute_command ( 'status --porcelain' ) match = result . each_line . select { | b | b . start_with? '?? ' } match . length > 0 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "引数の日付の入力画面に遷移する [CODESPLIT] def open_date ( date ) puts \"* start open date command: #{ @driver.current_url }: #{ @driver.find_element(:class, 'cxCmnTitleStr').text }\" if @verbose # 処理期間の入力 @driver . find_element ( :xpath , '//input[@name=\"StartYMD\"]' ) . send_keys ( BACKSPACE * 8 ) @driver . find_element ( :xpath , '//input[@name=\"StartYMD\"]' ) . send_keys ( date . strftime ( '%Y%m%d' ) ) @driver . find_element ( :xpath , '//input[@name=\"EndYMD\"]' ) . send_keys ( BACKSPACE * 8 ) @driver . find_element ( :xpath , '//input[@name=\"EndYMD\"]' ) . send_keys ( date . strftime ( '%Y%m%d' ) ) puts \"* input start date: #{  @driver.find_element(:xpath, '//input[@name=\"StartYMD\"]').attribute('value') }\" if @verbose puts \"* input end date: #{  @driver.find_element(:xpath, '//input[@name=\"EndYMD\"]').attribute('value') }\" if @verbose save_screenshot # 検索 @driver . find_element ( :xpath , '//input[@name=\"srchbutton\"]' ) . click puts \"* after click search button: #{ @driver.current_url }\" if @verbose save_screenshot end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the Msqid_ds object . See msgctl ( 2 ) . [CODESPLIT] def ipc_set ( msqid_ds ) unless Msqid_ds === msqid_ds raise ArgumentError , \"argument to ipc_set must be a Msqid_ds\" end check_result ( msgctl ( @msgid , IPC_SET , msqid_ds ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Receive a message of type + type + limited to + len + bytes or fewer . See msgrcv ( 2 ) . [CODESPLIT] def rcv ( type , size , flags = 0 ) res , mtype , mtext = msgrcv ( @msgid , size , type , flags ) check_result ( res ) mtext end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set each value in the semaphore set to the corresponding value in the Array + values + . See semctl ( 2 ) . [CODESPLIT] def setall ( values ) if values . length > @nsems raise ArgumentError , \"too many values (#{values.length}) for semaphore set (#{@nsems})\" end check_result ( semctl ( @semid , 0 , SETALL , values ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the Semid_ds object . See semctl ( 2 ) . [CODESPLIT] def ipc_set ( semid_ds ) unless Semid_ds === semid_ds raise ArgumentError , \"argument to ipc_set must be a Semid_ds\" end check_result ( semctl ( @semid , 0 , IPC_SET , semid_ds ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the Shmid_ds object . See shmctl ( 2 ) . [CODESPLIT] def ipc_set ( shmid_ds ) unless Shmid_ds === shmid_ds raise ArgumentError , \"argument to ipc_set must be a Shmid_ds\" end check_result ( shmctl ( @shmid , IPC_SET , shmid_ds ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Attach to a shared memory address object and return it . See shmat ( 2 ) . If + shmaddr + is nil the shared memory is attached at the first available address as selected by the system . See shmat ( 2 ) . [CODESPLIT] def attach ( shmaddr = nil , flags = 0 ) shmaddr = shmat ( @shmid , shmaddr , flags ) check_result ( shmaddr ) shmaddr end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- ------------------------------------------------------------------------- [CODESPLIT] def get_current_branch branches = execute_command ( 'branch --no-color' ) branch_match = branches . each_line . select { | b | b . start_with? '* ' } branch_match [ 0 ] . strip . gsub ( / \\* / , '' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------------------------- ------------------------------------------------------------------------- [CODESPLIT] def exists_locally? ( name ) branches = execute_command ( 'branch --no-color' ) . gsub ( / / , '' ) . lines . map ( :chomp ) . to_a branches . include? name end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "------------------------------------------------------------------------- ------------------------------------------------------------------------- [CODESPLIT] def exists_remotely? ( name , remote ) branches = execute_command ( 'branch -r --no-color' ) . gsub ( / / , '' ) . lines . map ( :chomp ) . to_a branches . include? \"#{remote}/#{name}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Makes sure status get instanciated on migration s instanciation Runs the migration following the direction sets the status the execution time and the last succesful_completion date [CODESPLIT] def run ( direction ) self . status . direction = direction # reset the status if the job is rerunnable and has already be completed self . status . reset! if self . class . rerunnable_safe? && completed? ( direction ) self . status . execution_time = time_it { self . send ( direction ) } self . status . last_succesful_completion = Time . now end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets an error to migration status [CODESPLIT] def failure = ( exception ) self . status . error = MigrationError . new ( :error_message => exception . message , :error_class => exception . class , :error_backtrace => exception . backtrace ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if a migration can be run [CODESPLIT] def is_runnable? ( direction ) self . class . rerunnable_safe? || ( direction == UP && status . current_status < status_complete ) || ( direction == DOWN && status . current_status > 0 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Checks if a migration as been completed [CODESPLIT] def completed? ( direction ) return false if self . status . execution_time == 0 ( direction == UP && self . status . current_status == self . status_complete ) || ( direction == DOWN && self . status . current_status == 0 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes a given block if the status has not being processed Then update the status [CODESPLIT] def step ( step_message = nil , step_status = 1 ) unless status . status_processed? ( status . direction , step_status ) self . status . message = step_message puts \"\\t #{step_message}\" yield if block_given? self . status . current_status += status . direction_to_i end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes a block and returns the time it took to be executed [CODESPLIT] def time_it puts \"Running #{self.class}[#{self.status.arguments}](#{self.status.direction})\" start = Time . now yield if block_given? end_time = Time . now - start puts \"Tasks #{self.class} executed in #{end_time} seconds. \\n\\n\" end_time end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prints a paragraphes [CODESPLIT] def super_print ( paragraphes , space_number = 50 , title = true ) puts format_paragraph ( space_number , title , paragraphes ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Transforms an array of paragraphes to a String using lines and columns Each paragraph is actually an Array of string where each string is a sentence of a given column if the sentence contains to much caractere the sentence will be splitted ( using whitespaces ) and written on several lines e g considering paragraphes = [[ id type ] [ id_1 test ]] format_paragraph will print : id type id_1 test [CODESPLIT] def format_paragraph ( space_number , title , * paragraphes ) column_size = paragraphes . max_by { | paragraph | paragraph . size } . size @full_text = Hash [ column_size . times . map { | i | [ i , [ ] ] } . flatten ( 1 ) ] paragraphes . each_with_index do | sentences , paragraph_number | sentences . each_with_index do | sentence , column | sentence = sentence . to_s words = sentence . gsub ( '=>' , ' => ' ) . split ( ' ' ) || '' if sentence . size > space_number && ( words ) . size > 1 new_sentence = \"\" words . each_with_index do | word , nb_word | if new_sentence . size + word . size < space_number new_sentence << word << ' ' else insert_line ( column , new_sentence ) unless new_sentence . empty? new_sentence = word << ' ' end end insert_line ( column , new_sentence ) unless new_sentence == @full_text [ column ] . last else insert_line ( column , sentence ) end end @full_text . each { | column , lines | ( @max_lines - lines . size ) . times { lines << '' } } space = paragraph_number == 0 && title ? \"/nbspace\" : \"\" @full_text . each { | column , lines | lines << space } end stringify_paragraph end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a String from a Hash of the following format { column_number = > [ lines ] } / nbspace is used to define a border [CODESPLIT] def stringify_paragraph ordered_lines = { } spaces = @full_text . map { | column , lines | lines . max_by { | sentence | sentence . size } . size } @full_text . each_with_index do | ( column , lines ) , i | lines . each_with_index do | line , line_number | if line == \"/nbspace\" ( ordered_lines [ line_number ] ||= \"\" ) << line . gsub ( \"/nbspace\" , \"-\" * ( spaces [ i ] + 4 ) ) else ( ordered_lines [ line_number ] ||= \"\" ) << line . to_s . ljust ( spaces [ i ] + 4 ) end end end ordered_lines . values . join ( \"\\n\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "---------------------- generate the grid javascript for a view options : : script = > true generates <script > tag ( true ) : ready = > true generates jquery ready function ( true ) [CODESPLIT] def to_javascript ( options = { } ) options = { :script => true , :ready => true } . merge ( options ) s = '' if options [ :script ] s << %Q^\n        <script type=\"text/javascript\">\n        var lastsel_#{dom_id};\n        ^ end s << js_helpers if options [ :ready ] s << %Q^\n        $(document).ready(function(){\n        ^ end s << jqgrid_javascript ( options ) if options [ :ready ] s << %Q^\n        });\n        ^ end if options [ :script ] s << %Q^\n        </script>\n        ^ end s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "generate the jqGrid initial values in json maps our attributes to jqGrid options ; omit values when same as jqGrid defaults [CODESPLIT] def jqgrid_properties vals = { } vals [ :ajaxGridOptions ] = ajax_grid_options if ajax_grid_options # data and request options vals [ :url ] = url if url vals [ :editurl ] = url if editable vals [ :restful ] = true if restful vals [ :inline_edit ] = inline_edit if inline_edit . present? vals [ :postData ] = { :grid => name , :datatype => data_type } #identify which grid making the request vals [ :colNames ] = colNames if colNames . present? vals [ :colModel ] = column_model if colModel . present? vals [ :datatype ] = data_type if data_type if data_format . present? case data_type when :xml vals [ :xmlReader ] = data_format when :json vals [ :jsonReader ] = data_format end end vals [ :loadonce ] = load_once if load_once vals [ :sortname ] = sort_by if sort_by vals [ :sortorder ] = sort_order if sort_order && sort_by vals [ :rowNum ] = rows_per_page if rows_per_page vals [ :rowTotal ] = total_rows if total_rows vals [ :page ] = current_page if current_page # grid options vals [ :height ] = height if height vals [ :gridview ] = grid_view # faster views, NOTE theres cases when this needs to be disabled case width_fit when :fitted #vals[:autowidth]    = false #default #vals[:shrinkToFit]  = true #default vals [ :forceFit ] = true vals [ :width ] = width if width when :scroll #vals[:autowidth]    = false #default vals [ :shrinkToFit ] = false #vals[:forceFit]     = #ignored by jqGrid vals [ :width ] = width if width else #when :fluid vals [ :autowidth ] = true #vals[:shrinkToFit]  = true #default vals [ :forceFit ] = true #vals[:width]        = is ignored vals [ :resizeStop ] = 'javascript: gridify_fluid_recalc_width' end vals [ :sortable ] = true if arranger_type . include? ( :sortable ) # header layer vals [ :caption ] = title if title vals [ :hidegrid ] = false unless collapsible vals [ :hiddengrid ] = true if collapsed # row formatting vals [ :altrows ] = true if alt_rows vals [ :altclass ] = alt_rows if alt_rows . is_a? ( String ) vals [ :rownumbers ] = true if row_numbers vals [ :rownumWidth ] = row_numbers if row_numbers . is_a? ( Numeric ) if inline_edit vals [ :scrollrows ] = true vals [ :multiselect ] = true if multi_select vals [ :onSelectRow ] = \"javascript: function(id, status) { if(id && id!==lastsel_#{dom_id}) { jQuery('##{dom_id}').jqGrid('restoreRow', lastsel_#{dom_id}); jQuery('##{dom_id}').jqGrid('editRow', id, true, #{inline_edit_handler}, #{error_handler}); lastsel_#{dom_id}=id}}\" elsif select_rows #.present? vals [ :scrollrows ] = true vals [ :onSelectRow ] = select_rows vals [ :multiselect ] = true if multi_select else vals [ :hoverrows ] = false vals [ :beforeSelectRow ] = \"javascript: function(){ false; }\" end # pager layer if pager vals [ :pager ] = \"##{pager}\" vals [ :viewrecords ] = true # display total records in the query (eg \"1 - 10 of 25\") vals [ :rowList ] = paging_choices if paging_controls . is_a? ( Hash ) # allow override of jqGrid pager options vals . merge! ( paging_controls ) elsif ! paging_controls vals [ :rowList ] = [ ] vals [ :pgbuttons ] = false vals [ :pginput ] = false vals [ :recordtext ] = \"{2} records\" end end if tree_grid vals [ :treeGrid ] = tree_grid vals [ :gridview ] = true vals [ :sortable ] = false end #subgrid if sub_grid vals [ :subGrid ] = sub_grid vals [ :subGridUrl ] = sub_grid_url vals [ :subGridModel ] = sub_grid_model vals [ :gridview ] = true end #events #vals[:serializeGridData] = serialize_grid_data if serialize_grid_data vals [ :loadonce ] = load_once if load_once # allow override of native jqGrid options vals . merge ( jqgrid_options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "----------------- [CODESPLIT] def jqgrid_javascript ( options = { } ) s = '' if table_to_grid s << %Q^\n        tableToGrid(\"##{dom_id}\", #{to_json});\n        ^ s << %Q^\n        grid_#{dom_id} = jQuery(\"##{dom_id}\")\n        ^ else s << %Q^\n        grid_#{dom_id} = jQuery(\"##{dom_id}\").jqGrid(#{to_json})\n        ^ end s << ';' # tag the grid as fluid so we can find it on resize events   if width_fit == :fluid s << %Q^\n        jQuery(\"##{dom_id}\").addClass(\"fluid\");\n        ^ end # override tableToGrid colmodel options as needed (sortable) #s << %Q^ .jqGrid('setColProp','Title',{sortable: false})^ # resize method if resizable s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('gridResize', #{resizable.to_json});\n        ^ end # pager buttons (navGrid) if pager nav_params = { 'edit' => edit_button . present? , 'add' => add_button . present? , 'del' => delete_button . present? , 'search' => search_button . present? || search_multiple . present? , 'view' => view_button . present? , 'refresh' => refresh_button . present? } . merge ( jqgrid_nav_options || { } ) s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('navGrid', '##{pager}',\n               #{nav_params.to_json},\n               #{edit_button_options.to_json_with_js},\n               #{add_button_options.to_json_with_js},\n               #{delete_button_options.to_json_with_js},\n               #{search_button_options.to_json_with_js},\n               #{view_button_options.to_json_with_js}\n               );\n        ^ end if arranger_type . include? ( :hide_show ) s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('navButtonAdd','##{pager}',{ \n               caption: \"Columns\", \n               title: \"Hide/Show Columns\", \n               onClickButton : function (){ jQuery(\"##{dom_id}\").jqGrid('setColumns',\n                 #{arranger_options(:hide_show).to_json_with_js} );\n               }\n        });\n        ^ end if arranger_type . include? ( :chooser ) # hackey way to build the string but gets it done chooser_code = %Q^ function (){ jQuery('##{dom_id}').jqGrid('columnChooser', {\n                          done : function (perm) {\n                            if (perm)  {\n                              this.jqGrid('remapColumns', perm, true);\n                              var gwdth = this.jqGrid('getGridParam','width');\n                              this.jqGrid('setGridWidth',gwdth);\n                            }\n                          } })}^ chooser_opts = { 'caption' => 'Columns' , 'title' => 'Arrange Columns' , 'onClickButton' => 'chooser_code' } . merge ( arranger_options ( :chooser ) ) s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('navButtonAdd','##{pager}', #{chooser_opts.to_json.gsub('\"chooser_code\"', chooser_code)} );\n        ^ end if search_toolbar # I wish we could put this in the header rather than the pager s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('navButtonAdd',\"##{pager}\", { caption:\"Toggle\", title:\"Toggle Search Toolbar\", buttonicon: 'ui-icon-pin-s', onClickButton: function(){ grid_#{dom_id}[0].toggleToolbar() } });\n        jQuery(\"##{dom_id}\").jqGrid('navButtonAdd',\"##{pager}\", { caption:\"Clear\", title:\"Clear Search\", buttonicon: 'ui-icon-refresh', onClickButton: function(){ grid_#{dom_id}[0].clearToolbar() } });\n        jQuery(\"##{dom_id}\").jqGrid('filterToolbar');\n        ^ end if sortable_rows # I wish we could put this in the header rather than the pager s << %Q^\n        jQuery(\"##{dom_id}\").jqGrid('sortableRows');\n        ^ end # TODO: built in event handlers, eg # loadError  # onSelectRow, onDblClickRow, onRightClickRow etc #unless search_toolbar == :visible #  s << %Q^ #  grid_#{dom_id}[0].toggleToolbar(); #  ^ #end # # keep page controls centered (jqgrid bug) [eg appears when :width_fit => :scroll] # s << %Q^ $(\"##{pager}_left\").css(\"width\", \"auto\"); ^ s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "normally we need to keep columns an ordered array sometimes its convenient to have a hash [CODESPLIT] def columns_hash colModel . inject ( { } ) { | h , col | h [ col . name ] = col ; h } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "# isnt there something in rails to do this already? def parse_options ( keys options ) ops = keys . inject ( {} ) do |h k| val = options . delete ( k ) h [ k ] = val unless val . nil? h end ops || {} end generate list of columns based on AR model option : : only or : except : col_options hash of hash of preset values for columns ( eg from cookie ) { : title = > { : width = > 98 }} [CODESPLIT] def build_columns ( klass , only , except , presets , include , actions ) #debugger # stringify only = Array ( only ) . map { | s | s . to_s } except = Array ( except ) . map { | s | s . to_s } presets ||= [ ] if presets . length > 0 hashed_defs = { } klass . columns . collect do | ar | #debugger next if only . present? && ! only . include? ( ar . name ) next if except . present? && except . include? ( ar . name ) hashed_defs [ ar . name ] = strct2args ( klass , ar ) end . compact if include include . each do | sub_model | my_model = sub_model . to_s if klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] my_class = klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] . to_s model = klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] . to_s else my_class = my_model end Object . const_get ( my_class . capitalize ) . columns . collect do | ar | #debugger next if only . present? && ! only . include? ( \"#{my_model}.#{ar.name}\" ) next if except . present? && except . include? ( \"#{my_model}.#{ar.name}\" ) hashed_defs [ \"#{my_model}.#{ar.name}\" ] = strct2args ( klass , ar ) end end end if actions hashed_defs [ \"row_actions\" ] = actions_args ( ) end # Take sequence from colModel self . colModel = [ ] presets . each do | col | # create column with default args merged with options given for this column self . colModel << GridColumn . new ( hashed_defs [ col [ :name ] ] . merge ( col ) ) end else # Take sequence from database definition self . colModel = klass . columns . collect do | ar | #debugger next if only . present? && ! only . include? ( ar . name ) next if except . present? && except . include? ( ar . name ) args = strct2args ( klass , ar ) # create column with default args merged with options given for this column GridColumn . new ( args ) end . compact if include include . each do | sub_model | my_model = sub_model . to_s if klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] my_class = klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] . to_s model = klass . inheritable_attributes [ :reflections ] [ sub_model ] . options [ :class_name ] . to_s else my_class = my_model end Object . const_get ( my_class . capitalize ) . columns . collect do | ar | #debugger next if only . present? && ! only . include? ( \"#{my_model}.#{ar.name}\" ) next if except . present? && except . include? ( \"#{my_model}.#{ar.name}\" ) args = strct2args ( klass , ar , \"#{my_model}.\" ) # create column with default args merged with options given for this column self . colModel << GridColumn . new ( args ) end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a list of attributes for related column ( align : right sortable : true resizable : false ... ) [CODESPLIT] def get_attributes ( column ) options = \",\" column . except ( :field , :label ) . each do | couple | if couple [ 0 ] == :editoptions options << \"editoptions:#{get_sub_options(couple[1])},\" elsif couple [ 0 ] == :formoptions options << \"formoptions:#{get_sub_options(couple[1])},\" elsif couple [ 0 ] == :searchoptions options << \"searchoptions:#{get_sub_options(couple[1])},\" elsif couple [ 0 ] == :editrules options << \"editrules:#{get_sub_options(couple[1])},\" else if couple [ 1 ] . class == String options << \"#{couple[0]}:'#{couple[1]}',\" else options << \"#{couple[0]}:#{couple[1]},\" end end end options . chop! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate options for editable fields ( value data width maxvalue cols rows ... ) [CODESPLIT] def get_sub_options ( editoptions ) options = \"{\" editoptions . each do | couple | if couple [ 0 ] == :value # :value => [[1, \"Rails\"], [2, \"Ruby\"], [3, \"jQuery\"]] options << %Q/value:\"/ couple [ 1 ] . each do | v | options << \"#{v[0]}:#{v[1]};\" end options . chop! << %Q/\",/ elsif couple [ 0 ] == :data # :data => [Category.all, :id, :title]) options << %Q/value:\"/ couple [ 1 ] . first . each do | obj | options << \"%s:%s;\" % [ obj . send ( couple [ 1 ] . second ) , obj . send ( couple [ 1 ] . third ) ] end options . chop! << %Q/\",/ else # :size => 30, :rows => 5, :maxlength => 20, ... if couple [ 1 ] . instance_of? ( Fixnum ) || couple [ 1 ] == 'true' || couple [ 1 ] == 'false' || couple [ 1 ] == true || couple [ 1 ] == false options << %Q/#{couple[0]}:#{couple[1]},/ else options << %Q/#{couple[0]}:\"#{couple[1]}\",/ end end end options . chop! << \"}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": and : or finds records based on request params e . g . params from jqGrid : _search do search ( true / false ) [ false ] : sidx sort index ( column to search on ) [ ] : sord sort direction ( desc / asc ) [ asc ] : nd ? : rows number of items to get [ 20 ] : page page number ( starts at 1 ) [ 1 ] [CODESPLIT] def update_from_params ( params ) params . symbolize_keys! params_to_rules params self . data_type = params [ :datatype ] if params [ :datatype ] self . sort_by = params [ :sidx ] if params [ :sidx ] self . sort_order = params [ :sord ] if params [ :sord ] self . current_page = params [ :page ] . to_i if params [ :page ] self . rows_per_page = params [ :rows ] . to_i if params [ :rows ] self . total_rows = params [ :total_rows ] . to_i if params [ :total_rows ] if tree_grid self . nodeid = params [ :nodeid ] . to_i if params [ :nodeid ] self . n_level = params [ :n_level ] . to_i if params [ :n_level ] self . n_left = params [ :n_left ] . to_i if params [ :n_left ] self . n_right = params [ :n_right ] . to_i if params [ :n_right ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return find args ( scope ) for current settings [CODESPLIT] def current_scope #debugger find_args = { } find_args [ :include ] = colInclude if colInclude if sort_by . present? && col = columns_hash [ sort_by ] if ( sort_by . include? \".\" ) # Workaround for :include and nested attributes field = sort_by . split ( '.' , 2 ) if field . length == 2 self . sort_by = field [ 0 ] . pluralize + \".\" + field [ 1 ] end end if case_sensitive || ! ( [ :string , :text ] . include? ( col . value_type ) ) find_args [ :order ] = \"#{sort_by} #{sort_order}\" else find_args [ :order ] = \"upper(#{sort_by}) #{sort_order}\" end end if total_rows . present? && total_rows > 0 find_args [ :limit ] = total_rows offset = ( current_page . to_i - 1 ) * rows_per_page if current_page . present? find_args [ :offset ] = offset if offset && offset > 0 elsif rows_per_page . present? && rows_per_page > 0 find_args [ :limit ] = rows_per_page offset = ( current_page . to_i - 1 ) * rows_per_page if current_page . present? find_args [ :offset ] = offset if offset && offset > 0 end cond = rules_to_conditions find_args [ :conditions ] = cond unless cond . blank? find_args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "grid doesnt nest attributes inside the resource could change this behavior in jqGrid see grid . postext . js ? http : // www . trirand . com / jqgridwiki / doku . php?id = wiki : post_data_module [CODESPLIT] def member_params ( params ) params . inject ( { } ) { | h , ( name , value ) | h [ name ] = value if columns_hash [ name ] ; h } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "params [ : filters ] = > { groupOp = > AND rules = > [ { data = > b op = > ge field = > title } { data = > f op = > le field = > title } ] } [CODESPLIT] def params_to_rules ( params ) #debugger if params [ :_search ] == 'true' || params [ :_search ] == true if params [ :filters ] # advanced search filters = ActiveSupport :: JSON . decode ( params [ :filters ] ) self . search_rules = filters [ 'rules' ] self . search_rules_op = filters [ 'groupOp' ] elsif params [ :searchField ] # simple search self . search_rules = [ { \"field\" => params [ :searchField ] , \"op\" => params [ :searchOper ] , \"data\" => params [ :searchString ] } ] else # toolbar search self . search_rules = [ ] self . search_rules_op = :and colModel . each do | col | name = col . name data = params [ name . to_sym ] self . search_rules << { \"field\" => name , \"op\" => \"cn\" , \"data\" => data } if data end end end search_rules end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "note we dont vals [ : foo ] = foo because dont want to bother generating key if its same as jqGrid default [CODESPLIT] def jqgrid_properties vals = { :name => name . gsub ( \".\" , \"__\" ) , :index => name } #xmlmap not required when same as :name # vals[:xmlmap]     = name          if data_type == :xml # vals[:jsonmap]    = name          if data_type == :json vals [ :label ] = label || name . titleize vals [ :resizable ] = false if resizable == false vals [ :fixed ] = fixed_width unless fixed_width == false vals [ :sortable ] = false if sortable == false vals [ :sort_type ] = jqgrid_type if sortable vals [ :search ] = false if searchable == false vals [ :editable ] = true if editable vals [ :align ] = align if align #vals[:align]      = 'right'       if [:integer, :float, :currency].include?(value_type) case value_type when :datetime vals [ :formatter ] = 'date' vals [ :formatoptions ] = { :srcformat => 'UniversalSortableDateTime' , :newformat => 'FullDateTime' } end vals [ :hidden ] = true if hidden vals [ :width ] = width if width vals [ :formatter ] = formatter if formatter vals [ :formatoptions ] = format_options if format_options vals [ :edittype ] = edit_type if editable && edit_type vals [ :formoptions ] = form_options if editable && form_options vals [ :editoptions ] = edit_options if editable && edit_options vals [ :editrules ] = validations if editable && validations vals [ :sort_type ] = sort_type if sort_type vals [ :search_type ] = search_type if search_type vals [ :search_rules ] = search_rules if search_rules vals [ :summaryType ] = summary_type if summary_type vals [ :summaryTpl ] = summary_tpl if summary_tpl # and more... vals end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "From http : // paydrotalks . com / posts / 45 - standard - json - response - for - rails - and - jquery [CODESPLIT] def render_json_response ( type , hash ) unless [ :ok , :redirect , :error ] . include? ( type ) raise \"Invalid json response type: #{type}\" end # To keep the structure consistent, we'll build the json  # structure with the default properties. # # This will also help other developers understand what  # is returned by the server by looking at this method. default_json_structure = { :status => type , :html => nil , :message => nil , :to => nil } . merge ( hash ) render_options = { :json => default_json_structure } render_options [ :status ] = 400 if type == :error render ( render_options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def reload_pages_if_needed if [CODESPLIT] def render @page_list . each do | page | page . render_to_file ( @config . dest_dir ) putc '.' ; $stdout . flush end @dir_list . each do | directory | src = File . join ( @config . pages_dir , directory ) dst = File . join ( @config . dest_dir , directory ) Render :: Asset . render_dir ( src , dst ) putc '.' ; $stdout . flush end if @config . short_paths render_short_path_symlinks end Render :: Apache . write_htaccess ( @config , @config . pages_dir , @config . dest_dir ) puts end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "find pages by a filter . filter is a string composing a path segment . For example : chat / security Which would match / services / chat / security but not / services / security [CODESPLIT] def find_pages ( filter ) filter = filter . downcase if filter =~ / \\/ / path = filter . split ( '/' ) . map { | segment | segment . gsub ( / / , '' ) } path_str = path . join ( '/' ) if ( page = @pages_by_path [ path_str ] ) page elsif matched_path = @page_paths . grep ( / #{ Regexp . escape ( path_str ) } / ) . first @pages_by_path [ matched_path ] elsif page = @pages_by_name [ path . last ] page else nil end elsif @pages_by_path [ filter ] @pages_by_path [ filter ] else @pages_by_name [ filter ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "registers a page with the site indexing the page path in our various hashes [CODESPLIT] def add_page ( page ) @pages_by_name [ page . name ] ||= page @pages_by_path [ page . path . join ( '/' ) ] = page add_aliases ( I18n . default_locale , page , @pages_by_path ) page . locales . each do | locale | next if locale == I18n . default_locale add_aliases ( locale , page , @pages_by_locale_path [ locale ] ) end @page_list << page end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "registers a page s aliases with the site [CODESPLIT] def add_aliases ( locale , page , path_hash ) page . aliases ( locale ) . each do | alias_path | alias_path_str = alias_path . join ( '/' ) if path_hash [ alias_path_str ] Amber . logger . warn \"WARNING: page `#{page.path.join('/')}` has alias `#{alias_path_str}`, but this path is already taken by `#{path_hash[alias_path_str].path.join('/')}` (locale = #{locale}).\" else path_hash [ alias_path_str ] = page end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns a hash containing all the automatically determined shortest paths for every page . the data structure looks like so : [CODESPLIT] def short_paths @short_paths ||= begin hash = { } pages_in_path_depth_order . each do | record | page = record [ :page ] path = record [ :path ] next if path . length == 1 path_prefix = path . dup path . length . times do | depth | path_prefix . shift path_str = path_prefix . join ( '/' ) if @pages_by_path [ path_str ] . nil? && hash [ path_str ] . nil? hash [ path_str ] = page end end end # debug: #hash.each do |path, record| #  puts \"#{record[:page].path.join('/')} => #{record[:path].join('/')}\" #end hash end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array like this : [CODESPLIT] def pages_in_path_depth_order paths = { } @page_list . each do | page | paths [ page . path ] ||= page locales = page . locales locales << I18n . default_locale unless locales . include? I18n . default_locale locales . each do | locale | page . aliases ( locale ) . each do | alias_path | paths [ alias_path ] ||= page end end end paths . collect { | path , page | { page : page , path : path } } . sort { | a , b | a [ :path ] . length <=> a [ :path ] . length } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "available options : [CODESPLIT] def order_by ( attr , options = { } ) locale = options [ :locale ] || I18n . locale direction = options [ :direction ] || :asc array = sort do | a , b | if direction == :desc a , b = b , a end a_prop = a . prop ( locale , attr ) b_prop = b . prop ( locale , attr ) if options [ :numeric ] a_prop = to_numeric ( a_prop ) b_prop = to_numeric ( b_prop ) end if a_prop . nil? && b_prop . nil? 0 elsif a_prop . nil? 1 elsif b_prop . nil? - 1 else a_prop <=> b_prop end end # remove pages from the results that have no value set for the attr array . delete_if do | page | page . prop ( locale , attr ) . nil? end return PageArray . new . replace array end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns an array of normalized aliases based on the : alias property defined for a page . [CODESPLIT] def aliases ( locale = I18n . default_locale ) @aliases ||= begin aliases_hash = Hash . new ( [ ] ) @props . locales . each do | l | aliases = @props . prop_without_inheritance ( l , :alias ) aliases_hash [ l ] = begin if aliases . nil? [ ] else [ aliases ] . flatten . collect { | alias_path | if alias_path =~ / \\/ / alias_path . sub ( / \\/ / , '' ) . split ( '/' ) elsif @parent @parent . path + [ alias_path ] else alias_path . split ( '/' ) end } end end end aliases_hash end @aliases [ locale ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "e . g . / home / user / dev / leap - public - site / app / views / pages / about - us / contact [CODESPLIT] def content_file ( locale ) content_files [ locale ] || content_files [ I18n . default_locale ] || content_files . values . first end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns [ name suffix ] called on new page initialization [CODESPLIT] def parse_source_file_name ( name ) matches = name . match ( / \\. #{ LOCALES_RE } \\. #{ PAGE_SUFFIXES_RE } / ) if matches [ matches [ 'name' ] , matches [ 'suffix' ] ] else [ name , nil ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns the files that compose the content for this page a different file for each locale ( or no locale ) [CODESPLIT] def content_files @content_files ||= begin if @simple_page directory = File . dirname ( @file_path ) regexp = SIMPLE_FILE_MATCH_RE . call ( @name ) else directory = @file_path regexp = LOCALE_FILE_MATCH_RE end hsh = { } Dir . foreach ( directory ) do | file | if file && match = regexp . match ( file ) locale = match [ 'locale' ] || I18n . default_locale hsh [ locale . to_sym ] = File . join ( directory , file ) end end hsh end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns an array of files in the folder that corresponds to this page that are not other pages . in other words the assets in this folder [CODESPLIT] def asset_files if @simple_page [ ] else Dir . foreach ( @file_path ) . collect { | file | is_asset = file && file !~ / \\. #{ PAGE_SUFFIXES_RE } / && file !~ / #{ VAR_FILE_MATCH_RE } / && ! File . directory? ( File . join ( @file_path , file ) ) file if is_asset } . compact end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def self . relative_to_rails_view_root ( absolute_path ) if Rails . root absolute = Pathname . new ( absolute_path ) rails_view_root = Pathname . new ( Rails . root + app / views ) absolute . relative_path_from ( rails_view_root ) . to_s end end [CODESPLIT] def load_properties props = PageProperties . new ( self ) content_files . each do | locale , content_file | if type_from_path ( content_file ) == :haml props . eval ( File . read ( content_file , :encoding => 'UTF-8' ) , locale ) else headers , excerpt = parse_headers ( content_file ) props . eval ( headers , locale ) if ! excerpt . empty? props . set_prop ( locale , \"excerpt\" , excerpt ) end props . set_prop ( locale , \"content_type\" , type_from_path ( content_file ) ) end cleanup_properties ( props , locale ) end unless props . prop_without_inheritance ( I18n . default_locale , :name ) props . set_prop ( I18n . default_locale , :name , self . name ) end return props end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "parses a content_file s property headers and tries to extract the first paragraph . [CODESPLIT] def parse_headers ( content_file ) headers = [ ] para1 = [ ] para2 = [ ] file_type = type_from_path ( content_file ) File . open ( content_file , :encoding => 'UTF-8' ) do | f | while ( line = f . gets ) =~ / \\w / if line !~ / / line = '- ' + line end headers << line end # eat empty lines while line = f . gets break unless line =~ / \\s / end # grab first two paragraphs para1 << line while line = f . gets break if line =~ / \\s / para1 << line end while line = f . gets break if line =~ / \\s / para2 << line end end headers = headers . join para1 = para1 . join para2 = para2 . join excerpt = \"\" # pick the first non-heading paragraph. # this is stupid, and chokes on nested headings. # but is also cheap and fast :) if file_type == :textile if para1 =~ / \\. / excerpt = para2 else excerpt = para1 end elsif file_type == :markdown if para1 =~ / / || para1 =~ / \\s /m excerpt = para2 else excerpt = para1 end end return [ headers , excerpt ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "VARIABLES Variables are associated with a page but unlike properties they are not inheritable . Variables are defined in a separate file . [CODESPLIT] def variable_files if @simple_page directory = File . dirname ( @file_path ) regexp = SIMPLE_VAR_MATCH_RE . call ( @name ) else directory = @file_path regexp = VAR_FILE_MATCH_RE end hsh = { } Dir . foreach ( directory ) do | file | if file && match = regexp . match ( file ) locale = match [ 'locale' ] || I18n . default_locale hsh [ locale . to_sym ] = File . join ( directory , file ) end end hsh end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "public methods [CODESPLIT] def submenu ( item_name = nil ) if item_name self . children . detect { | child | child . name == item_name } else self . children end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns true if this menu item is the terminus menu item for path . ( meaning that there are no children that match more path segments ) [CODESPLIT] def leaf_for_path? ( path ) return false unless path_prefix_of? ( path ) next_path_segment = ( path - self . path ) . first return false if next_path_segment . nil? return ! children . detect { | i | i . name == next_path_segment } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns the last list of children at the specified depth [CODESPLIT] def last_menu_at_depth ( depth ) menu = self depth . times { menu = menu . children . last } menu end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns anchor text from heading text . e . g . First Heading! = > first - heading [CODESPLIT] def anchor_text ( heading_text ) text = nameize ( strip_html_tags ( heading_text ) ) text_with_suffix = text i = 2 while @heading_anchors [ text_with_suffix ] text_with_suffix = \"#{text}-#{i}\" i += 1 end @heading_anchors [ text_with_suffix ] = true text_with_suffix end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "convert any string to one suitable for a url . resist the urge to translit non - ascii slugs to ascii . it is always much better to keep strings as utf8 . [CODESPLIT] def nameize ( str ) str = str . dup str . gsub! ( / \\w / , '' ) # remove html entitities str . gsub! ( / /u , '' ) # remove non-word characters (using unicode definition of a word char) str . strip! str . downcase! # upper case characters in urls are confusing str . gsub! ( / \\  /u , '-' ) # spaces to dashes, preferred separator char everywhere CGI . escape ( str ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "removes all html markup [CODESPLIT] def strip_html_tags ( html ) Nokogiri :: HTML :: DocumentFragment . parse ( html , 'UTF-8' ) . children . collect { | child | child . inner_text } . join end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "remove <a name = x > < / a > from html but leaves all other tags in place . [CODESPLIT] def strip_anchors ( html ) Nokogiri :: HTML :: DocumentFragment . parse ( html , 'UTF-8' ) . children . collect { | child | if child . name == \"text\" child . inner_text elsif child . name != 'a' || ! child . attributes . detect { | atr | atr [ 0 ] == 'name' } child . to_s end } . join end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "generates nokogiri html node tree from this toc [CODESPLIT] def populate_node ( node , options ) @children . each do | item | li = node . document . create_element ( \"li\" ) li . add_child ( li . document . create_element ( \"a\" , item . text , :href => \"#{options[:href_base]}##{item.anchor}\" ) ) if item . children . any? ul = li . document . create_element ( options [ :tag ] ) item . populate_node ( ul , options ) li . add_child ( ul ) end node . add_child ( li ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "generates html string from this toc [CODESPLIT] def to_html ( options = { } ) html = [ ] tag = options [ :tag ] indent = options [ :indent ] || 0 str = options [ :indent_str ] || \"  \" html << '%s<%s>' % [ ( str indent ) , tag ] @children . each do | item | html << '%s<li>' % ( str ( indent + 1 ) ) html << '%s<a href=\"%s#%s\">%s</a>' % [ str ( indent + 2 ) , options [ :href_base ] , item . anchor , item . text ] if item . children . any? html << item . to_html ( { :indent => indent + 2 , :indent_str => str , :tag => tag , :href_base => options [ :href_base ] } ) end html << '%s</li>' % ( str ( indent + 1 ) ) end html << '%s</%s>' % [ ( str indent ) , tag ] html . join ( \"\\n\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the appropriate TocItem for appending a new item at a particular heading level . [CODESPLIT] def parent_for ( heading ) heading = heading [ 1 ] . to_i if heading . is_a? ( String ) if children . any? && children . last . level < heading children . last . parent_for ( heading ) else self end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "INSTANCE METHODS [CODESPLIT] def map ( path_to_directory_source , options = { } ) path , root_dir = path_to_directory_source . to_a . first config = self . load ( @site , root_dir , { :path_prefix => path } ) @site . add_config ( config ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieves meta data from the file using exiftool and returned in a hash allowing for complex conversion rules . [CODESPLIT] def meta if ` #{ EXIF_UTILITY } ` . empty? { } else @meta_data ||= ` #{ EXIF_UTILITY } #{ @from_file } ` . split ( \"\\n\" ) . inject ( { } ) { | hash , element | hash . merge ( ( ( split = element . split ( ':' ) ) && split . first . strip . downcase . gsub ( / / , \"_\" ) . to_sym ) => ( split . shift && split ) . join ( ':' ) . strip ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the numeric type ID for a string so you don t have to manage magic numbers in your application . The argument can be a string or a symbol and is case insensitive . Underscores will be converted to spaces . [CODESPLIT] def type_id ( which ) which = which . to_s . humanize unless which . kind_of? ( String ) which . downcase! case which when 'alliance' then 16159 when 'character' then 1377 when 'corporation' then 2 when 'constellation' then 4 when 'region' then 3 when 'solar system' , 'solarsystem' then 5 when 'station' then 3867 else raise ArgumentError , \"Unknown type: #{which}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a hyperlink that results in the show info dialog being displayed on the client s screen . If item_id is given the show info window will open for that item . [CODESPLIT] def link_to_info ( text , type_id , item_id = nil , * args ) function = \"CCPEVE.showInfo(#{type_id.inspect}\" function . concat \", #{item_id.inspect}\" if item_id function . concat \")\" link_to_function text , function , args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a hyperlink that results in showing the route to the destination_id from the source_id . If source_id is not given the source system is taken to be the system the user is currently in . [CODESPLIT] def link_to_route ( text , destination_id , source_id = nil , * args ) function = \"CCPEVE.showRouteTo(#{destination_id.inspect}\" function . concat \", #{source_id.inspect}\" if source_id function . concat \")\" link_to_function text , function , args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Produces a hyperlink that will result in a pop - up a trust prompt in the client allowing the user to either grant the trust request ignore it or always ignore trust requests from your site . [CODESPLIT] def link_to_trust_request ( text , trust_url = \"http://#{request.host}/\" , * args ) trust_url = url_for ( trust_url . merge ( :only_path => false ) ) if trust_url . kind_of? ( Hash ) link_to_function text , \"CCPEVE.requestTrust(#{trust_url.inspect})\" , args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This will generate a method call that produces a pop - up a trust prompt in the client allowing the user to either grant the trust request ignore it or always ignore trust requests from your site . [CODESPLIT] def request_trust ( trust_url = \"http://#{request.host}/\" , * args ) trust_url = url_for ( trust_url . merge ( :only_path => false ) ) if trust_url . kind_of? ( Hash ) javascript_tag \"CCPEVE.requestTrust(#{trust_url.inspect});\" , args end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "render without layout possibly with via a rails request [CODESPLIT] def render_to_file ( dest_dir , options = { } ) render_content_files ( dest_dir , options ) render_assets ( dest_dir ) @props . locales . each do | locale | if aliases ( locale ) . any? link_page_aliases ( dest_dir , aliases ( locale ) , locale ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "creates symlinks for aliases to this page . called by Page#render_to_file and Site#render_short_path_aliases [CODESPLIT] def link_page_aliases ( dest_dir , alias_paths , locale = I18n . default_locale ) alias_paths . each do | alias_path | alias_file_path = File . join ( dest_dir , alias_path ) #if locale != I18n.default_locale #  alias_file_path += \".#{locale}\" #end alias_file_path = Pathname . new ( alias_file_path ) page_file_path = Pathname . new ( File . join ( dest_dir , @path ) ) symlink ( page_file_path , alias_file_path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "RAILS def render_locale ( renderer locale ) if renderer && is_haml_template? ( locale ) renderer . render_to_string ( : template = > self . template_path ( locale ) : layout = > false ) . html_safe else render_static_locale ( locale ) . html_safe end end RAILS def render_static_locale ( locale ) content_files . each do |file_locale content_file| if locale == file_locale return Render :: View . new ( self self . mount_point ) . render ( { file : content_file } { locale : file_locale } ) end end raise MissingTemplate . new ( template_path ( locale )) end called only by render_to_file [CODESPLIT] def render_assets ( dest_dir ) asset_files . each do | asset_file | src_file = File . join ( @file_path , asset_file ) dst_file = File . join ( dest_dir , @path , asset_file ) Render :: Asset . render ( src_file , dst_file ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "create a symlink . arguments must be of type Pathname . [CODESPLIT] def symlink ( from_path , to_path ) to_path = realpath ( to_path ) target = from_path . relative_path_from ( to_path ) . to_s . sub ( / \\. \\. \\/ / , '' ) if ! to_path . dirname . directory? Amber . logger . warn { \"On page `#{@file_path}`, the parent directories for alias name `#{to_path}` don't exist. Skipping alias.\" } return end if to_path . exist? && to_path . symlink? File . unlink ( to_path ) end if ! to_path . exist? Amber . logger . debug { \"Symlink #{to_path} => #{target}\" } FileUtils . ln_s ( target , to_path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "called only by render_to_file [CODESPLIT] def render_content_files ( dest_dir , options ) view = Render :: View . new ( self , @config ) @config . locales . each do | file_locale | content_file = content_file ( file_locale ) next unless content_file dest = destination_file ( dest_dir , file_locale ) unless Dir . exist? ( File . dirname ( dest ) ) FileUtils . mkdir_p ( File . dirname ( dest ) ) end if options [ :force ] || ! File . exist? ( dest ) || File . mtime ( content_file ) > File . mtime ( dest ) File . open ( dest , 'w' ) do | f | layout = @props . layout || 'default' f . write view . render ( { page : self , layout : layout } , { locale : file_locale } ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Destroys given bucket . Raises an S3 :: Error :: BucketNotEmpty exception if the bucket is not empty . You can destroy non - empty bucket passing true ( to force destroy ) = begin def destroy ( force = false ) delete_bucket true rescue Error :: BucketNotEmpty if force objects . destroy_all retry else raise end end = end [CODESPLIT] def destroy ( force = false ) if objects . any? if force objects . destroy_all delete_bucket true else raise end else delete_bucket true end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options available : animal breed size sex location shelterid [CODESPLIT] def random_pet ( options = { } ) query = options . merge ( :output => 'full' ) response = perform_get ( \"/pet.getRandom\" , query ) Pet . new ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options available : breed size sex age offset count [CODESPLIT] def find_pets ( animal_type , location , options = { } ) query = options . merge ( :animal => animal_type , :location => location ) response = perform_get ( \"/pet.find\" , query ) Pet . multiple ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options available : name offset count [CODESPLIT] def find_shelters ( location , options = { } ) query = options . merge ( :location => location ) response = perform_get ( \"/shelter.find\" , query ) Shelter . multiple ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options available : offset count [CODESPLIT] def find_shelters_by_breed ( animal_type , breed , options = { } ) query = options . merge ( :animal => animal_type , :breed => breed ) response = perform_get ( \"/shelter.listByBreed\" , query ) Shelter . multiple ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Options available : status offset count [CODESPLIT] def shelter_pets ( id , options = { } ) query = options . merge ( :id => id ) response = perform_get ( \"/shelter.getPets\" , query ) Pet . multiple ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Friend a user [CODESPLIT] def friend name , friend_id , note = nil friend_wrapper ( api_name = name , api_container = @userid , api_note = note , api_type = \"friend\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a listing of user posts . Some options may be restricted [CODESPLIT] def get_user_listing username , opts = { } opts [ :type ] = 'overview' if opts [ :type ] . nil? url = \"/user/%s%s.json\" % [ username , ( '/' + opts [ :type ] if opts [ :type ] != 'overview' ) ] opts . delete :type query = opts get ( url , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Posts a comment to the site [CODESPLIT] def comment text , id logged_in? post ( '/api/comment' , body : { text : text , thing_id : id , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a listing of things which have the provided URL . You can use a plain url or a reddit link id to get reposts of said link @note Using { Listings#search } is probably better for url lookups [CODESPLIT] def info opts = { } query = { limit : 100 } query . merge! opts get ( '/api/info.json' , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Submit a link or self post [CODESPLIT] def submit title , subreddit , opts = { } logged_in? post = { title : title , sr : subreddit , uh : @modhash , kind : ( opts [ :url ] ? \"link\" : \"self\" ) , api_type : 'json' } post . merge! opts post ( '/api/submit' , body : post ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Vote on a comment or link [CODESPLIT] def vote direction , id logged_in? post ( '/api/vote' , body : { id : id , dir : direction , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determine whether or not an answer is correct [CODESPLIT] def correct? ( str ) str = str . is_a? ( String ) ? str : str . to_s str == ( @answer . is_a? ( String ) ? @answer : @answer . to_s ) # don't change @answer type end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Propose a gotcha to the user - question and answer hash [CODESPLIT] def gotcha ( options = { } ) options [ :label_options ] ||= { } options [ :text_field_options ] ||= { } if gotcha = Gotcha . random field = \"gotcha_response[#{gotcha.class.name.to_s}-#{Digest::MD5.hexdigest(gotcha.class.down_transform(gotcha.answer))}]\" ( label_tag field , gotcha . question , options [ :label_options ] ) + \"\\n\" + ( text_field_tag field , nil , options [ :text_field_options ] ) else raise \"No Gotchas Installed\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes an image from a subreddit . This is for css not removing posts [CODESPLIT] def delete_image subreddit , image_name logged_in? post ( '/api/delete_sr_image' , body : { r : subreddit , img_name : image_name , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@todo test if every param is actually required Sets subreddit settings . [CODESPLIT] def subreddit_settings subreddit , opts = { } logged_in? params = { type : 'public' , link_type : 'any' , lang : 'en' , r : subreddit , uh : @modhash , allow_top : true , show_media : true , over_18 : false , api_type : 'json' } params . merge! opts post ( '/api/site_admin' , body : params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the subreddit stylesheet [CODESPLIT] def set_stylesheet stylesheet , subreddit logged_in? post ( '/api/subreddit_stylesheet' , body : { op : 'save' , r : subreddit , stylesheet_contents : stylesheet , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Subscribe to a subreddit [CODESPLIT] def subscribe subreddit , action = \"sub\" logged_in? post ( '/api/subscribe' , body : { action : action , sr : subreddit , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get subreddits I have [CODESPLIT] def my_reddits opts = { } logged_in? url = \"/reddits/mine/%s.json\" % ( opts [ :condition ] if opts [ :condition ] ) opts . delete :condition query = opts get ( url , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a list of subreddits [CODESPLIT] def get_reddits opts = { } url = \"/reddits/%s.json\" % ( opts [ :condition ] if opts [ :condition ] ) opts . delete :condition query = opts get ( url , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Search subreddits [CODESPLIT] def search_reddits q , opts = { } query = { q : q } query . merge! opts get ( '/reddits/search.json' , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a moderator to the subreddit [CODESPLIT] def add_moderator container , user , subreddit friend_wrapper container : container , name : user , r : subreddit , type : \"moderator\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a contributor to the subreddit [CODESPLIT] def add_contributor container , user , subreddit friend_wrapper container : container , name : user , r : subreddit , type : \"contributor\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ban a user from a subreddit [CODESPLIT] def ban_user container , user , subreddit friend_wrapper container : container , name : user , r : subreddit , type : \"banned\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove a moderator from a subreddit [CODESPLIT] def remove_moderator container , user , subreddit unfriend_wrapper container : container , name : user , r : subreddit , type : \"moderator\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Remove a contributor from a subreddit [CODESPLIT] def remove_contributor container , user , subreddit unfriend_wrapper container : container , name : user , r : subreddit , type : \"contributor\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Unban a user from a subreddit [CODESPLIT] def unban_user container , user , subreddit unfriend_wrapper container : container , name : user , r : subreddit , type : \"banned\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "HTTParty get wrapper . This serves to clean up code as well as throw webserver errors wherever needed [CODESPLIT] def get * args , & block response = self . class . get args , block raise WebserverError , response . code unless response . code == 200 response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "HTTParty POST wrapper . This serves to clean up code as well as throw webserver errors wherever needed same as { #get } [CODESPLIT] def post * args , & block response = self . class . post args , block raise WebserverError , response . code unless response . code == 200 response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Posts to / api / friend . This method exists because there are tons of things that use this See http : // www . reddit . com / dev / api#POST_api_friend for details [CODESPLIT] def friend_wrapper opts = { } logged_in? params = { uh : @modhash , api_type : 'json' } params . merge! opts post ( '/api/friend' , body : params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Log into a reddit account . You need to do this to use any restricted or write APIs [CODESPLIT] def log_in username , password login = post ( \"/api/login\" , :body => { user : username , passwd : password , api_type : 'json' } ) errors = login [ 'json' ] [ 'errors' ] raise errors [ 0 ] [ 1 ] unless errors . size == 0 set_cookies login . headers [ 'set-cookie' ] @modhash = login [ 'json' ] [ 'data' ] [ 'modhash' ] @username = username @userid = 't2_' + get ( '/api/me.json' ) [ 'data' ] [ 'id' ] return login end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Auth into reddit via modhash and cookie . This has the advantage of not throttling you if you call it a lot [CODESPLIT] def auth modhash , cookies set_cookies cookies @modhash = modhash meinfo = get ( \"/api/me.json\" ) @username = meinfo [ 'data' ] [ 'name' ] @userid = 't2_' + meinfo [ 'data' ] [ 'id' ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Invalidates all other reddit session cookies and updates the current one . This will log out all other reddit clients as described in the [ reddit API ] ( http : // www . reddit . com / dev / api#POST_api_clear_sessions ) [CODESPLIT] def clear_sessions password logged_in? clear = post ( '/api/clear_sessions' , body : { curpass : password , dest : @baseurl , uh : @modhash , api_type : 'json' } ) set_cookies clear . headers [ 'set-cookie' ] return clear end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes the current user . This requires a password for security reasons . [CODESPLIT] def delete_user password , reason = \"deleted by script command\" logged_in? delete = post ( '/api/delete_user' , body : { confirm : true , delete_message : reason , passwd : password , uh : @modhash , user : @username , api_type : 'json' } ) return delete end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Changes the current user s password / email . [CODESPLIT] def update_user currentPass , newPass , email = nil logged_in? params = { curpass : currentPass , newpass : newPass , uh : @modhash , verify : true , verpass : newPass , api_type : 'json' } params [ :email ] = email if email update = post ( '/api/update' , body : params ) set_cookies update . headers [ 'set-cookie' ] return update end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extend strings and / or symbols to create queries easier [CODESPLIT] def monkey_patch! ( * args ) args = %w{ symbol string } if args . empty? args . each do | arg | case arg . to_s . downcase . to_sym when :symbol if monkey_patched? ( :symbol ) puts \"Symbol has already been monkey patched!\" false else Symbol . send :include , OrderExtension Symbol . send :include , ConditionalExtension Symbol . send :include , FieldOperatorExtension Symbol . send :include , BundledFunctionExtension monkey_patched << :symbol true end when :string if monkey_patched? ( :string ) puts \"String has already been monkey patched!\" false else String . send :include , OrderExtension String . send :include , ConditionalExtension String . send :include , FieldOperatorExtension String . send :include , BundledFunctionExtension monkey_patched << :string true end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Send a private message To reply to PM use { LinksComments#comment } with the PM id as the link id [CODESPLIT] def send_pm to , subject , text logged_in? post ( '/api/compose.json' , body : { to : to , subject : subject , text : text , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets a listing of PMs [CODESPLIT] def get_messages where = \"inbox\" , opts = { } query = { mark : false } query . merge! opts get ( \"/message/#{where}.json\" , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Clear all the flair templates of a particular type [CODESPLIT] def clear_flair_templates type , subreddit logged_in? post ( '/api/clearflairtemplates' , body : { flair_type : type , r : subreddit , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes a user s flair [CODESPLIT] def delete_user_flair user , subreddit logged_in? post ( '/api/deleteflair' , body : { name : user , r : subreddit , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes a flair template by ID . [CODESPLIT] def delete_flair_template id , subreddit logged_in? post ( '/api/deleteflairtemplate' , body : { flair_template_id : id , r : subreddit , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets flair on a thing currently supports links and users . Must specify ** either ** link * or * user ** not ** both [CODESPLIT] def flair subreddit , opts = { } logged_in? params = { r : subreddit , uh : @modhash , api_type : 'json' } params . merge! opts post ( '/api/flair' , body : params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Configures flair options for a subreddit . All options are required [CODESPLIT] def flair_config subreddit , opts = { } logged_in? options = { flair_enabled : true , flair_position : 'right' , flair_self_assign_enabled : false , link_flair_position : 'right' , link_flair_self_assign_enabled : false , uh : @modhash , r : subreddit , api_type : 'json' } options . merge! opts post ( '/api/flairconfig' , body : options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Post flair in a CSV file to reddit [CODESPLIT] def flair_csv csv , subreddit logged_in? post ( '/api/flaircsv.json' , body : { flair_csv : csv , r : subreddit , uh : @modhash } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Downloads flair from the subreddit This is limited to 1000 per request use before / after to get pages [CODESPLIT] def get_flair_list subreddit , opts = { } logged_in? query = { limit : 1000 , uh : @modhash } query . merge! opts get ( \"/r/#{subreddit}/api/flairlist.json\" , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create or edit a flair template . [CODESPLIT] def flair_template subreddit , opts = { } logged_in? params = { flair_type : 'USER_FLAIR' , text_editable : false , uh : @modhash , r : subreddit , api_type : 'json' } params . merge! opts post ( '/api/flairtemplate' , body : params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Select a flair template and apply it to a user or link [CODESPLIT] def select_flair_template template_id , subreddit , opts = { } logged_in? params = { flair_template_id : template_id , uh : @modhash , r : subreddit , api_type : 'json' } params . merge! opts post ( '/api/selectflair' , body : params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Toggle flair on and off for a subreddit [CODESPLIT] def flair_toggle enabled , subreddit logged_in? post ( '/api/setflairenabled' , body : { flair_enabled : enabled , uh : @modhash , r : subreddit , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a comment listing from the site [CODESPLIT] def get_comments opts = { } query = { limit : 100 } query . merge! opts url = \"%s/comments/%s%s.json\" % [ ( '/r/' + opts [ :subreddit ] if opts [ :subreddit ] ) , opts [ :link_id ] , ( '/blah/' + opts [ :comment_id ] if opts [ :comment_id ] ) ] get ( url , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets a listing of links from reddit . [CODESPLIT] def get_listing opts = { } # Build the basic url url = \"%s/%s.json\" % [ ( '/r/' + opts [ :subreddit ] if opts [ :subreddit ] ) , ( opts [ :page ] if opts [ :page ] ) ] # Delete subreddit and page from the hash, they dont belong in the query [ :subreddit , :page ] . each { | k | opts . delete k } query = opts # Make the request get ( url , query : query ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Search reddit [CODESPLIT] def search query , opts = { } # This supports searches with and without a subreddit url = \"%s/search.json\" % ( '/r/' + opts [ :subreddit ] if opts [ :subreddit ] ) # Construct the query httpquery = { q : query } opts . delete :subreddit httpquery . merge! opts get ( url , query : httpquery ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "检查身份证合法性 [CODESPLIT] def is_valid? ( id_card ) code = get_id_argument ( id_card ) return false unless check_address_code ( code [ :address_code ] ) return false unless check_birthday_code ( code [ :birthday_code ] ) return false unless check_order_code ( code [ :order_code ] ) return true if code [ :type ] == 15 check_bit = generate_check_bit ( code [ :body ] ) return false if check_bit . nil? || ( code [ :check_bit ] != check_bit ) true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "获取身份证详细信息 [CODESPLIT] def get_info ( id_card ) return false unless is_valid? ( id_card ) code = get_id_argument ( id_card ) address_info = get_address_info ( code [ :address_code ] ) { address_code : code [ :address_code ] , address : IdValidator :: Concern :: Func . format_address_info ( address_info ) , abandoned : check_is_abandoned ( code [ :address_code ] ) , birthday_code : IdValidator :: Concern :: Func . format_birthday_code ( code [ :birthday_code ] ) , constellation : get_constellation ( code [ :birthday_code ] ) , chinese_zodiac : get_chinese_zodiac ( code [ :birthday_code ] ) , sex : code [ :order_code ] . to_i % 2 , length : code [ :type ] , check_bit : code [ :check_bit ] } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "构建虚假身份证信息 [CODESPLIT] def fake_id ( eighteen = true , address = nil , birthday = nil , sex = nil ) address_code = generate_address_code ( address ) birthday_code = generate_birthday_code ( birthday ) order_code = generate_order_code ( sex ) return address_code + birthday_code [ 2 .. - 1 ] + order_code unless eighteen body = address_code + birthday_code + order_code check_bit = generate_check_bit ( body ) body + check_bit end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "身份证号升级（15位 升级为 18位） [CODESPLIT] def upgrade_id ( id_card ) return false unless ( id_card . length == 15 && is_valid? ( id_card ) ) code = get_id_argument ( id_card ) body = code [ :address_code ] + code [ :birthday_code ] + code [ :order_code ] body + generate_check_bit ( body ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Go through each response using the down_transform of the original class ( as long as it is a subclass of Gotcha :: Base ) and compare the hash to the hash of the value [CODESPLIT] def determine_gotcha_validity ( expected_gotcha_count = 1 ) return false unless params [ :gotcha_response ] . kind_of? ( Enumerable ) return false unless params [ :gotcha_response ] . count == expected_gotcha_count params [ :gotcha_response ] . all? do | ident , value | type , hash = ident . split '-' return false unless Object . const_defined? ( type ) return false unless ( klass = Object . const_get ( type ) ) < Gotcha :: Base Digest :: MD5 . hexdigest ( klass . down_transform ( value ) ) == hash end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / ParameterLists [CODESPLIT] def process_filter_assoc_param ( attr , metadata , assoc_values , value , opts ) attr_elems = attr . split ( '.' ) assoc_name = attr_elems [ 0 ] . strip . to_sym assoc_metadata = metadata [ assoc_name ] || metadata [ ModelApi :: Utils . ext_query_attr ( assoc_name , opts ) ] || { } key = assoc_metadata [ :key ] return unless key . present? && ModelApi :: Utils . eval_bool ( assoc_metadata [ :filter ] , opts ) assoc_filter_params = ( assoc_values [ key ] ||= { } ) assoc_filter_params [ attr_elems [ 1 .. - 1 ] . join ( '.' ) ] = value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / ParameterLists [CODESPLIT] def apply_filter_param ( attr_metadata , collection , opts = { } ) raw_value = ( opts [ :attr_values ] || params ) [ attr_metadata [ :key ] ] filter_table = opts [ :filter_table ] klass = opts [ :class ] || ModelApi :: Utils . find_class ( collection , opts ) if raw_value . is_a? ( Hash ) && raw_value . include? ( '0' ) operator_value_pairs = filter_process_param_array ( params_array ( raw_value ) , attr_metadata , opts ) else operator_value_pairs = filter_process_param ( raw_value , attr_metadata , opts ) end if ( column = resolve_key_to_column ( klass , attr_metadata ) ) . present? operator_value_pairs . each do | operator , value | if operator == '=' && filter_table . blank? collection = collection . where ( column => value ) else table_name = ( filter_table || klass . table_name ) . to_s . delete ( '`' ) column = column . to_s . delete ( '`' ) if value . is_a? ( Array ) operator = 'IN' value = value . map { | _v | format_value_for_query ( column , value , klass ) } value = \"(#{value.map { |v| \"'#{v.to_s.gsub(\"'\", \"''\")}'\" }.join(',')})\" else value = \"'#{value.gsub(\"'\", \"''\")}'\" end collection = collection . where ( \"`#{table_name}`.`#{column}` #{operator} #{value}\" ) end end elsif ( key = attr_metadata [ :key ] ) . present? opts [ :result_filters ] [ key ] = operator_value_pairs if opts . include? ( :result_filters ) end collection end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Intentionally disabling parameter list length check for private / internal method rubocop : disable Metrics / ParameterLists [CODESPLIT] def process_sort_param_assoc ( attr , metadata , sort_order , assoc_sorts , opts ) attr_elems = attr . split ( '.' ) assoc_name = attr_elems [ 0 ] . strip . to_sym assoc_metadata = metadata [ assoc_name ] || { } key = assoc_metadata [ :key ] return unless key . present? && ModelApi :: Utils . eval_bool ( assoc_metadata [ :sort ] , opts ) assoc_sort_params = ( assoc_sorts [ key ] ||= { } ) assoc_sort_params [ attr_elems [ 1 .. - 1 ] . join ( '.' ) ] = sort_order end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / ParameterLists [CODESPLIT] def filter_process_param ( raw_value , attr_metadata , opts ) raw_value = raw_value . to_s . strip array = nil if raw_value . starts_with? ( '[' ) && raw_value . ends_with? ( ']' ) array = JSON . parse ( raw_value ) rescue nil array = array . is_a? ( Array ) ? array . map ( :to_s ) : nil end if array . nil? if attr_metadata . include? ( :filter_delimiter ) delimiter = attr_metadata [ :filter_delimiter ] else delimiter = ',' end array = raw_value . split ( delimiter ) if raw_value . include? ( delimiter ) end return filter_process_param_array ( array , attr_metadata , opts ) unless array . nil? operator , value = parse_filter_operator ( raw_value ) [ [ operator , ModelApi :: Utils . transform_value ( value , attr_metadata [ :parse ] , opts ) ] ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Distinguish a thing [CODESPLIT] def distinguish id , how = \"yes\" logged_in? hows = %w{ yes no admin special } post ( '/api/distinguish' , body : { id : id , how : how , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes a thing [CODESPLIT] def remove id , spam = false logged_in? post ( '/api/remove' , body : { id : id , spam : spam , uh : @modhash , api_type : 'json' } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets a moderation log This is a tricky function and may break a lot . Blame the lack of a real api [CODESPLIT] def get_modlog subreddit , opts = { } logged_in? options = { limit : 100 } . merge opts data = Nokogiri :: HTML . parse ( get ( \"/r/#{subreddit}/about/log\" , query : options ) . body ) . css ( '.modactionlisting tr' ) processed = { data : [ ] , first : data [ 0 ] [ 'data-fullname' ] , first_date : Time . parse ( data [ 0 ] . children [ 0 ] . child [ 'datetime' ] ) , last : data [ - 1 ] [ 'data-fullname' ] , last_date : Time . parse ( data [ - 1 ] . children [ 0 ] . child [ 'datetime' ] ) , } data . each do | tr | processed [ :data ] << { fullname : tr [ 'data-fullname' ] , time : Time . parse ( tr . children [ 0 ] . child [ 'datetime' ] ) , author : tr . children [ 1 ] . child . content , action : tr . children [ 2 ] . child [ 'class' ] . split [ 1 ] , description : tr . children [ 3 ] . content , href : tr . children [ 3 ] . css ( 'a' ) . count == 0 ? nil : tr . children [ 3 ] . css ( 'a' ) [ 0 ] [ 'href' ] } end return processed end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the modqueue or a subset of it ( dear god ) [CODESPLIT] def get_modqueue subreddit , opts = { } logged_in? options = { limit : 100 } . merge opts get ( \"/r/#{subreddit}/about/modqueue.json\" , query : options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Upon a failure at the first URL will automatically retry with the second & third ones before finally raising an exception Returns an HTTPResponse object [CODESPLIT] def post ( query_params ) servers ||= SERVERS . map { | hostname | \"https://#{hostname}/minfraud/chargeback\" } url = URI . parse ( servers . shift ) req = Net :: HTTP :: Post . new ( url . path , initheader = { 'Content-Type' => 'application/json' } ) req . basic_auth Maxmind :: user_id , Maxmind :: license_key req . body = query_params h = Net :: HTTP . new ( url . host , url . port ) h . use_ssl = true h . verify_mode = OpenSSL :: SSL :: VERIFY_NONE # set some timeouts h . open_timeout = 60 # this blocks forever by default, lets be a bit less crazy. h . read_timeout = self . class . timeout || DefaultTimeout h . ssl_timeout = self . class . timeout || DefaultTimeout h . start { | http | http . request ( req ) } rescue Exception => e retry if servers . size > 0 raise e end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / clips GET / clips . json GET / clips . xml [CODESPLIT] def clips # get all clips, with the newest clip first if params [ :lang ] . nil? @clips = Clip . public . order ( 'created_at DESC' ) . page ( params [ :page ] ) else @clips = Clip . language_for_public ( params [ :lang ] ) . order ( 'created_at DESC' ) . page ( params [ :page ] ) end @updated_at = @clips . first . updated_at unless @clips . empty? respond_to do | format | format . html format . atom format . json { render json : @clips } format . xml { render xml : @clips } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / new GET / new . json GET / new . xml [CODESPLIT] def new @clip = Clip . new respond_to do | format | format . html # new.html.erb format . json { render json : @clip } format . xml { render xml : @clip } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST / create POST / create . json POST / create . xml [CODESPLIT] def create @clip = Clip . new begin @clip = Clip . new ( params [ :clip ] ) rescue ActiveModel :: MassAssignmentSecurity :: Error => error @clip . errors . add ( \"Security -\" , error . message ) end respond_to do | format | if @clip . errors . empty? && @clip . valid? && @clip . save format . html { redirect_to @clip } format . json { render json : @clip , status : :created , location : @post } format . xml { render xml : @clip , status : :created , location : @post } else # didn't pass validation format . html { render :new } format . json { render json : @clip . errors , status : :unprocessable_entity } format . xml { render xml : @clip . errors , status : :unprocessable_entity } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST / [ id ] POST / [ id ] . json POST / [ id ] . xml [CODESPLIT] def show @clip = Clip . where ( \"id = :id and (expires is null OR expires > :now)\" , { :id => params [ :id ] , :now => DateTime . now } ) . first if @clip . nil? # Most likely the clip is expired, take advantage of this time to # clean up all expired clips, then display error page Clip . delete_expired respond_to do | format | @clip = Clip . new @clip . errors . add ( \"Clip id\" , \"is either invalid or it has expired.\" ) format . html { render :expired , status : :not_found } format . text { render text : @clip . errors , status : :not_found } format . json { render json : @clip . errors , status : :not_found } format . xml { render xml : @clip . errors , status : :not_found } end return end respond_to do | format | format . html format . text { render text : @clip . clip . html_safe } format . json { render json : @clip } format . xml { render xml : @clip } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / search?search_term = [ term ] GET / search . json?search_term = [ term ] GET / search . xml?search_term = [ term ] [CODESPLIT] def search @clips = Clip . search ( params [ :search_term ] ) . page ( params [ :page ] ) respond_to do | format | format . html { render :clips } format . json { render json : @clips } format . xml { render xml : @clips } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Setter to convert user s choice of A Week etc . to an actual DateTime [CODESPLIT] def lifespan = ( lifespan ) @lifespan = lifespan @@lifespans . each_with_index do | span , index | if span [ 0 ] == lifespan && lifespan != \"Forever\" self . expires = DateTime . now . advance ( @@lifespans [ index ] [ 1 ] ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates the div for the clip [CODESPLIT] def div cr_scanner = CodeRay . scan ( self . clip , self . language ) # Only show line numbers if its greater than 1 if cr_scanner . loc <= 1 return cr_scanner . div else return cr_scanner . div ( :line_numbers => :table ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "adds instance method to the class . Method accepts any instance of builder and returns it after rendering . @param [ Symbol ] method_name @yield [ self ] builder_block is evaluated inside builder and accepts instance of a rendered object as parameter @example class User # ... include HammerBuilder :: Helper [CODESPLIT] def builder ( method_name , & builder_block ) define_method ( method_name ) do | builder , * args | builder . dive ( self , args , builder_block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "sets instance variables when block is yielded [CODESPLIT] def set_variables ( instance_variables ) instance_variables . each { | name , value | instance_variable_set ( \"@#{name}\" , value ) } yield ( self ) instance_variables . each { | name , _ | remove_instance_variable ( \"@#{name}\" ) } self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "renders + object + with + method + [CODESPLIT] def render ( object , method , * args , & block ) object . __send__ method , self , args , block self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "renders js [CODESPLIT] def js ( js , options = { } ) use_cdata = options . delete ( :cdata ) || false script ( { :type => \"text/javascript\" } . merge ( options ) ) { use_cdata ? cdata ( js ) : text ( js ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "joins and renders + collection + with + glue + [CODESPLIT] def join ( collection , glue = nil , & it ) # TODO as helper? two block method call #join(collection, &item).with(&glue) glue_block = case glue when String lambda { text glue } when Proc glue else lambda { } end collection . each_with_index do | obj , i | glue_block . call ( ) if i > 0 obj . is_a? ( Proc ) ? obj . call : it . call ( obj ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param file [ String ] target file @param ref [ String ] git ref @param new_line [ String ] file s ending new line [CODESPLIT] def fetch_file ( file = Lock :: FILE_NAME , ref = REF , new_line = NEW_LINE ) super ( file , ref , new_line ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "returns + builder + back into pool * DONT * forget to lose the reference to the + builder + [CODESPLIT] def release ( builder ) raise TypeError unless builder . is_a? @klass builder . reset @pool . push builder nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the cursor position to the specified + x + and + y + locations in the console output buffer . If + y + is nil the cursor is positioned at + x + on the current line . [CODESPLIT] def set_cursor_position ( x , y ) if stdout && x && y coord = y << 16 | x self . set_console_cursor_position ( stdout , coord ) == 0 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new ISBM ProviderPublication client . [CODESPLIT] def open_session ( uri ) validate_presence_of uri , 'Channel URI' response = @client . call ( :open_publication_session , message : { 'ChannelURI' => uri } ) response . to_hash [ :open_publication_session_response ] [ :session_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Posts a publication message . [CODESPLIT] def post_publication ( session_id , content , topics , expiry = nil ) validate_presence_of session_id , 'Session Id' validate_presence_of content , 'Content' validate_presence_of topics , 'Topics' validate_xml content topics = [ topics ] . flatten # Use Builder to generate XML body as we need to concatenate XML message content xml = Builder :: XmlMarkup . new xml . isbm :SessionID , session_id xml . isbm :MessageContent do xml << content end topics . each do | topic | xml . isbm :Topic , topic end duration = expiry . to_s xml . isbm :Expiry , duration unless duration . nil? response = @client . call ( :post_publication , message : xml . target! ) response . to_hash [ :post_publication_response ] [ :message_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Expires a posted publication message . [CODESPLIT] def expire_publication ( session_id , message_id ) validate_presence_of session_id , 'Session Id' validate_presence_of message_id , 'Message Id' @client . call ( :expire_publication , message : { 'SessionID' => session_id , 'MessageID' => message_id } ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new ISBM client . [CODESPLIT] def validate_presence_of ( value , name ) if value . respond_to? ( :each ) value . each do | v | if v . blank? raise ArgumentError , \"Values in #{name} must not be blank\" end end else if value . blank? raise ArgumentError , \"#{name} must not be blank\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Validates the well formedness of the XML string and raises an error if any errors are encountered . [CODESPLIT] def validate_xml ( xml ) doc = Nokogiri . XML ( xml ) raise ArgumentError , \"XML is not well formed: #{xml}\" unless doc . errors . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates an IsbmAdaptor :: Message from a ISBM response . [CODESPLIT] def extract_message ( response ) # Extract the message element # e.g. /Envelope/Body/ReadPublicationResponse/PublicationMessage soap_ns = 'http://schemas.xmlsoap.org/soap/envelope/' message = response . doc . xpath ( 's:Envelope/s:Body' , s : soap_ns ) . first . first_element_child . first_element_child return nil unless message id = message . element_children [ 0 ] . text content = message . element_children [ 1 ] . first_element_child topics = message . element_children [ 2 .. - 1 ] . map { | e | e . text } # Retain any ancestor namespaces in case they are applicable for the element # and/or children. This is because content.to_xml does not output ancestor # namespaces. # There may be unnecessary namespaces carried across (e.g. ISBM, SOAP), but we # can't tell if the content uses them without parsing the content itself. content . namespaces . each do | key , value | # Don't replace default namespace if it already exists next if key == 'xmlns' && content [ 'xmlns' ] content [ key ] = value end # Wrap content in a separate Nokogiri document. This allows the ability to # validate the content against a schema. doc = Nokogiri :: XML ( content . to_xml ) IsbmAdaptor :: Message . new ( id , doc , topics ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets default values for certain Savon options . [CODESPLIT] def default_savon_options ( options ) options [ :logger ] = Rails . logger if options [ :logger ] . nil? && defined? ( Rails ) options [ :log ] = false if options [ :log ] . nil? options [ :pretty_print_xml ] = true if options [ :pretty_print_xml ] . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Reads the first message if any in the session queue . [CODESPLIT] def read_publication ( session_id ) validate_presence_of session_id , 'Session Id' response = @client . call ( :read_publication , message : { 'SessionID' => session_id } ) extract_message ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new ISBM ConsumerRequest client . [CODESPLIT] def open_session ( uri , listener_url = nil ) validate_presence_of uri , 'Channel URI' message = { 'ChannelURI' => uri } message [ 'ListenerURL' ] = listener_url if listener_url response = @client . call ( :open_consumer_request_session , message : message ) response . to_hash [ :open_consumer_request_session_response ] [ :session_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Posts a request message on a channel . [CODESPLIT] def post_request ( session_id , content , topic , expiry = nil ) validate_presence_of session_id , 'Session Id' validate_presence_of content , 'Content' validate_presence_of topic , 'Topic' validate_xml content # Use Builder to generate XML body as we need to concatenate XML message content xml = Builder :: XmlMarkup . new xml . isbm :SessionID , session_id xml . isbm :MessageContent do xml << content end xml . isbm :Topic , topic duration = expiry . to_s xml . isbm :Expiry , duration unless duration . nil? response = @client . call ( :post_request , message : xml . target! ) response . to_hash [ :post_request_response ] [ :message_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Expires a posted request message . [CODESPLIT] def expire_request ( session_id , message_id ) validate_presence_of session_id , 'Session Id' validate_presence_of message_id , 'Message Id' @client . call ( :expire_request , message : { 'SessionID' => session_id , 'MessageID' => message_id } ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the first response message if any in the message queue associated with the request . [CODESPLIT] def read_response ( session_id , request_message_id ) validate_presence_of session_id , 'Session Id' validate_presence_of request_message_id , 'Request Message Id' message = { 'SessionID' => session_id , 'RequestMessageID' => request_message_id } response = @client . call ( :read_response , message : message ) extract_message ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes the first response message if any in the message queue associated with the request . [CODESPLIT] def remove_response ( session_id , request_message_id ) validate_presence_of session_id , 'Session Id' validate_presence_of request_message_id , 'Request Message Id' message = { 'SessionID' => session_id , 'RequestMessageID' => request_message_id } @client . call ( :remove_response , message : message ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new ISBM ProviderRequest client . [CODESPLIT] def open_session ( uri , topics , listener_url = nil , xpath_expression = nil , xpath_namespaces = [ ] ) validate_presence_of uri , 'Channel URI' validate_presence_of topics , 'Topics' validate_presence_of xpath_expression , 'XPath Expression' if xpath_namespaces . present? topics = [ topics ] . flatten # Use Builder to generate XML body as we may have multiple Topic elements xml = Builder :: XmlMarkup . new xml . isbm :ChannelURI , uri topics . each do | topic | xml . isbm :Topic , topic end xml . isbm :ListenerURL , listener_url unless listener_url . nil? xml . isbm :XPathExpression , xpath_expression unless xpath_expression . nil? xpath_namespaces . each do | prefix , name | xml . isbm :XPathNamespace do xml . isbm :NamespacePrefix , prefix xml . isbm :NamespaceName , name end end response = @client . call ( :open_provider_request_session , message : xml . target! ) response . to_hash [ :open_provider_request_session_response ] [ :session_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the first request message in the message queue for the session . Note : this service does not remove the message from the message queue . [CODESPLIT] def read_request ( session_id ) validate_presence_of session_id , 'Session Id' message = { 'SessionID' => session_id } response = @client . call ( :read_request , message : message ) extract_message ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Posts a response message on a channel . [CODESPLIT] def post_response ( session_id , request_message_id , content ) validate_presence_of session_id , 'Session Id' validate_presence_of request_message_id , 'Request Message Id' validate_presence_of content , 'Content' validate_xml content # Use Builder to generate XML body as we need to concatenate XML message content xml = Builder :: XmlMarkup . new xml . isbm :SessionID , session_id xml . isbm :RequestMessageID , request_message_id xml . isbm :MessageContent do xml << content end response = @client . call ( :post_response , message : xml . target! ) response . to_hash [ :post_response_response ] [ :message_id ] . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new ISBM ChannelManagement client . [CODESPLIT] def create_channel ( uri , type , description = nil , tokens = { } ) validate_presence_of uri , 'Channel URI' validate_presence_of type , 'Channel Type' channel_type = type . to_s . downcase . capitalize validate_inclusion_in channel_type , IsbmAdaptor :: Channel :: TYPES , 'Channel Type' message = { 'ChannelURI' => uri , 'ChannelType' => channel_type } message [ 'ChannelDescription' ] = description unless description . nil? message [ 'SecurityToken' ] = security_token_hash ( tokens ) if tokens . any? @client . call ( :create_channel , message : message ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds security tokens to a channel . [CODESPLIT] def add_security_tokens ( uri , tokens = { } ) validate_presence_of uri , 'Channel URI' validate_presence_of tokens , 'Security Tokens' message = { 'ChannelURI' => uri , 'SecurityToken' => security_token_hash ( tokens ) } @client . call ( :add_security_tokens , message : message ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes security tokens from a channel . [CODESPLIT] def remove_security_tokens ( uri , tokens = { } ) validate_presence_of uri , 'Channel URI' validate_presence_of tokens , 'Security Tokens' message = { 'ChannelURI' => uri , 'SecurityToken' => security_token_hash ( tokens ) } @client . call ( :remove_security_tokens , message : message ) return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets information about the specified channel . [CODESPLIT] def get_channel ( uri , & block ) validate_presence_of uri , 'Channel URI' response = @client . call ( :get_channel , message : { 'ChannelURI' => uri } , block ) hash = response . to_hash [ :get_channel_response ] [ :channel ] IsbmAdaptor :: Channel . from_hash ( hash ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets information about all channels . [CODESPLIT] def get_channels ( & block ) response = @client . call ( :get_channels , { } , block ) channels = response . to_hash [ :get_channels_response ] [ :channel ] channels = [ channels ] . compact unless channels . is_a? ( Array ) channels . map do | hash | IsbmAdaptor :: Channel . from_hash ( hash ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns tokens mapped to wsse : UsernameToken hash . [CODESPLIT] def security_token_hash ( tokens ) wsse = Akami . wsse tokens . map do | username , password | wsse . credentials ( username , password ) # Extract the UsernameToken element username_token = wsse . send ( :wsse_username_token ) [ 'wsse:Security' ] # Restore the wsse namespace ns = { 'xmlns:wsse' => Akami :: WSSE :: WSE_NAMESPACE } username_token [ :attributes! ] [ 'wsse:UsernameToken' ] . merge! ( ns ) username_token end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "== Instance Methods ===================================================== Update the record and then push those changes to the i18n backend [CODESPLIT] def update_and_update_backend ( params = { } ) self . translated_at = Time . zone . now if self . phrase_untranslated? result = self . update ( params ) if result self . update_backend end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Will update the i18n backend if it has been configured [CODESPLIT] def update_backend if Idioma . configuration . redis_backend if i18n_value . present? Idioma :: RedisBackend . update_phrase ( self ) else Idioma :: RedisBackend . delete_phrase ( self ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the cursor position to the specified + x + and + y + locations in the console output buffer . If + y + is nil the cursor is positioned at + x + on the current line . [CODESPLIT] def set_cursor_position ( x , y ) if stdout && x && y coord = Coord . new ( x , y ) self . set_console_cursor_position ( stdout , coord ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / phrases [CODESPLIT] def index params [ :locale_eq ] ||= I18n . default_locale scope = Phrase . where ( locale : params [ :locale_eq ] ) if params [ :q ] . present? scope = scope . where ( \"i18n_key ilike ? OR i18n_value ilike ?\" , \"%#{params[:q]}%\" , \"%#{params[:q]}%\" ) end respond_to do | format | format . html { @phrases = scope . paginate ( :page => params [ :page ] ) } format . csv { render text : PhraseExporter . to_csv ( scope ) } format . yaml { render text : PhraseExporter . to_yaml ( scope ) } format . json { @phrases = scope . paginate ( :page => params [ :page ] ) render json : { meta : { pagination : { current_page : @phrases . current_page , per_page : @phrases . per_page , total_entries : @phrases . total_entries } } , phrases : @phrases } } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "PATCH / PUT / phrases / 1 [CODESPLIT] def update result = @phrase . update_and_update_backend ( phrase_params ) respond_to do | format | format . html { if result redirect_to [ :edit , @phrase ] else render :edit end } format . json { if result render json : @phrase else render json : { errors : @phrase . errors . messages } . merge ( @phrase . attributes ) , status : :bad_request end } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Use callbacks to share common setup or constraints between actions . [CODESPLIT] def set_phrase @phrase = Phrase . find ( params [ :id ] ) rescue ActiveRecord :: RecordNotFound respond_to do | format | format . json { render json : { } . to_json , status : :not_found } format . html { flash [ :error ] = t ( 'idioma.record_not_found' ) redirect_to phrases_path } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new Duration based on specified time components . [CODESPLIT] def to_s date = [ ] date << \"#{@years}Y\" unless @years . nil? date << \"#{@months}M\" unless @months . nil? date << \"#{@days}D\" unless @days . nil? time = [ ] time << \"#{@hours}H\" unless @hours . nil? time << \"#{@minutes}M\" unless @minutes . nil? time << \"#{@seconds}S\" unless @seconds . nil? result = nil if ! date . empty? || ! time . empty? result = 'P' result += date . join unless date . empty? result += 'T' + time . join unless time . empty? end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the latitude of this point ; signed numeric degrees if no format otherwise format & dp [CODESPLIT] def to_lat format = :dms , dp = 0 return lat if ! format GeoUnits :: Converter . to_lat lat , format , dp end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the longitude of this point ; signed numeric degrees if no format otherwise format & dp as per Geo . toLon () [CODESPLIT] def to_lon format , dp return lon if ! format GeoUnits :: Converter . to_lon lon , format , dp end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a string representation of this point ; format and dp as per lat () / lon () [CODESPLIT] def to_s format = :dms , dp = 0 format ||= :dms return '-,-' if ! lat || ! lon _lat = GeoUnits :: Converter . to_lat lat , format , dp _lon = GeoUnits :: Converter . to_lon lon , format , dp \"#{_lat}, #{_lon}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the list of projects available to the authenticated user . [CODESPLIT] def projects if @projects . nil? response = self . get ( \"projects\" ) @projects = response . collect { | project_json | Project . new ( project_json ) } end @projects end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the details for a specific project . [CODESPLIT] def project ( id ) @url = \"projects/#{id}\" raise OptimizelyError :: NoProjectID , \"A Project ID is required to retrieve the project.\" if id . nil? response = self . get ( @url ) Project . new ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the list of experiments for a specified project . [CODESPLIT] def experiments ( project_id ) raise OptimizelyError :: NoProjectID , \"A Project ID is required to retrieve experiments.\" if project_id . nil? response = self . get ( \"projects/#{project_id}/experiments\" ) response . collect { | response_json | Experiment . new ( response_json ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the details for a specific experiment . [CODESPLIT] def experiment ( id ) @url = \"experiments/#{id}\" raise OptimizelyError :: NoExperimentID , \"An Experiment ID is required to retrieve the experiment.\" if id . nil? response = self . get ( @url ) Experiment . new ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the stats for a specific experiment . [CODESPLIT] def stats ( experiment_id ) @url = \"experiments/#{experiment_id}/stats\" raise OptimizelyError :: NoExperimentID , \"An Experiment ID is required to retrieve the stats.\" if experiment_id . nil? response = self . get ( @url ) response . collect { | response_json | Stat . new ( response_json ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the list of variations for a specified experiment . [CODESPLIT] def variations ( experiment_id ) raise OptimizelyError :: NoExperimentID , \"An Experiment ID is required to retrieve variations.\" if experiment_id . nil? response = self . get ( \"experiments/#{experiment_id}/variations\" ) response . collect { | variation_json | Variation . new ( variation_json ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the details for a specific variation . [CODESPLIT] def variation ( id ) @url = \"variations/#{id}\" raise OptimizelyError :: NoVariationID , \"A Variation ID is required to retrieve the variation.\" if id . nil? response = self . get ( @url ) Variation . new ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the list of audiences for a specified project . [CODESPLIT] def audiences ( project_id ) raise OptimizelyError :: NoProjectID , \"A Project ID is required to retrieve audiences.\" if project_id . nil? response = self . get ( \"projects/#{project_id}/audiences\" ) response . collect { | audience_json | Audience . new ( audience_json ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the details for a specific audience . [CODESPLIT] def audience ( id ) @url = \"audiences/#{id}\" raise OptimizelyError :: NoAudienceID , \"An Audience ID is required to retrieve the audience.\" if id . nil? response = self . get ( @url ) Audience . new ( response ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the parsed JSON data for a request that is done to the Optimizely REST API . [CODESPLIT] def get ( url ) uri = URI . parse ( \"#{BASE_URL}#{url}/\" ) https = Net :: HTTP . new ( uri . host , uri . port ) https . read_timeout = @options [ :timeout ] if @options [ :timeout ] https . verify_mode = OpenSSL :: SSL :: VERIFY_NONE https . use_ssl = true request = Net :: HTTP :: Get . new ( uri . request_uri , @headers ) response = https . request ( request ) # Response code error checking if response . code != '200' check_response ( response . code , response . body ) else parse_json ( response . body ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "compliments of the ruby way [CODESPLIT] def nth_wday ( n , aWday , month , year ) wday = aWday - 1 if ( ! n . between? 1 , 5 ) or ( ! wday . between? 0 , 6 ) or ( ! month . between? 1 , 12 ) raise ArgumentError end t = Time . zone . local year , month , 1 first = t . wday if first == wday fwd = 1 elsif first < wday fwd = wday - first + 1 elsif first > wday fwd = ( wday + 7 ) - first + 1 end target = fwd + ( n - 1 ) * 7 begin t2 = Time . zone . local year , month , target rescue ArgumentError return nil end if t2 . mday == target t2 else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Connects to the Tyrant table listening at the given host and port . [CODESPLIT] def lget ( * keys ) h = keys . flatten . inject ( { } ) { | hh , k | hh [ k ] = nil ; hh } r = @db . mget ( h ) raise 'lget failure' if r == - 1 h end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calls a lua embedded function ( http : // tokyocabinet . sourceforge . net / tyrantdoc / #luaext ) [CODESPLIT] def ext ( func_name , key = '' , value = '' , opts = { } ) @db . ext ( func_name . to_s , key . to_s , value . to_s , compute_ext_opts ( opts ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a random number of a specified Byte length returns Bignum [CODESPLIT] def get_random_number ( bytes ) RbNaCl :: Util . bin2hex ( RbNaCl :: Random . random_bytes ( bytes ) . to_s ) . to_i ( 16 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a random number of a exact bitlength returns Bignum [CODESPLIT] def get_random_number_with_bitlength ( bits ) byte_length = ( bits / 8.0 ) . ceil + 10 random_num = get_random_number ( byte_length ) random_num_bin_str = random_num . to_s ( 2 ) # Get 1's and 0's # Slice off only the bits we require, convert Bits to Numeric (Bignum) random_num_bin_str . slice ( 0 , bits ) . to_i ( 2 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Supports #miller_rabin_prime? [CODESPLIT] def mod_exp ( n , e , mod ) fail ArgumentError , 'negative exponent' if e < 0 prod = 1 base = n % mod until e . zero? prod = ( prod * base ) % mod if e . odd? e >>= 1 base = ( base * base ) % mod end prod end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "An implementation of the miller - rabin primality test . See : http : // primes . utm . edu / prove / merged . html See : http : // rosettacode . org / wiki / Miller - Rabin_primality_test#Ruby See : https : // crypto . stackexchange . com / questions / 71 / how - can - i - generate - large - prime - numbers - for - rsa See : https : // en . wikipedia . org / wiki / Miller%E2%80%93Rabin_primality_test [CODESPLIT] def miller_rabin_prime? ( n , g = 1000 ) return false if n == 1 return true if n == 2 d = n - 1 s = 0 while d . even? d /= 2 s += 1 end g . times do a = 2 + rand ( n - 4 ) x = mod_exp ( a , d , n ) # x = (a**d) % n next if x == 1 || x == n - 1 ( 1 .. s - 1 ) . each do x = mod_exp ( x , 2 , n ) # x = (x**2) % n return false if x == 1 break if x == n - 1 end return false if x != n - 1 end true # probably end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds a random prime number of * at least * bitlength Validate primeness using the miller - rabin primality test . Increment through odd numbers to test candidates until a good prime is found . [CODESPLIT] def get_prime_number ( bitlength ) prime_cand = get_random_number_with_bitlength ( bitlength + 1 ) prime_cand += 1 if prime_cand . even? # loop, adding 2 to keep it odd, until prime_cand is prime. ( prime_cand += 2 ) until miller_rabin_prime? ( prime_cand ) prime_cand end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "FIXME : Needs focused tests Evaluate the polynomial at x . [CODESPLIT] def evaluate_polynomial_at ( x , coefficients , prime ) result = 0 coefficients . each_with_index do | c , i | result += c * ( x ** i ) result %= prime end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate the Modular Inverse . See : http : // rosettacode . org / wiki / Modular_inverse#Ruby Based on pseudo code from http : // en . wikipedia . org / wiki / Extended_Euclidean_algorithm#Iterative_method_2 [CODESPLIT] def invmod ( e , et ) g , x = extended_gcd ( e , et ) fail ArgumentError , 'Teh maths are broken!' if g != 1 x % et end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "FIXME : Needs focused tests Part of the Lagrange interpolation . This is l_j ( 0 ) i . e . \\ prod_ { x_j \\ neq x_i } \\ frac { - x_i } { x_j - x_i } for more information compare Wikipedia : http : // en . wikipedia . org / wiki / Lagrange_form [CODESPLIT] def lagrange ( x , shares ) prime = shares . first . prime other_shares = shares . reject { | s | s . x == x } results = other_shares . map do | s | minus_xi = - s . x # was OpenSSL::BN#mod_inverse one_over_xj_minus_xi = invmod ( x - s . x , prime ) # was OpenSSL::BN#mod_mul : (self * other) % m ( minus_xi * one_over_xj_minus_xi ) % prime end results . reduce { | a , e | ( a * e ) % prime } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Same args as new () but can take a block form that will close the db when done . Similar to File . open () . ( via Zev and JEG2 ) [CODESPLIT] def open ( * args ) db = new ( args ) if block_given? begin yield db ensure db . close end else db end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets an index on a column of the table . [CODESPLIT] def set_index ( column_name , * types ) column_name = column_name == :pk ? '' : column_name . to_s i = types . inject ( 0 ) { | ii , t | ii | INDEX_TYPES [ t ] } @db . setindex ( column_name , i ) || raise_error end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inserts a record in the table db [CODESPLIT] def []= ( pk , h_or_a ) pk = pk . to_s m = h_or_a . is_a? ( Hash ) ? h_or_a : Hash [ h_or_a ] m = Rufus :: Tokyo . h_or_a_to_s ( m ) #verify_value(m) @db . put ( pk , m ) || raise_error end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes an entry in the table [CODESPLIT] def delete ( k ) k = k . to_s val = @db [ k ] return nil unless val @db . out ( k ) || raise_error val end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a hash { key = > record } of all the records matching the given keys . [CODESPLIT] def lget ( * keys ) keys = Rufus :: Tokyo :: h_or_a_to_s ( keys . flatten ) if @db . respond_to? ( :mget ) @db . mget ( keys ) else keys . inject ( { } ) { | h , k | v = self [ k ] ; h [ k ] = v if v ; h } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepares a query instance ( block is optional ) [CODESPLIT] def prepare_query ( & block ) q = TableQuery . new ( table_query_class , self ) block . call ( q ) if block q end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A #search a la ruby - tokyotyrant ( http : // github . com / actsasflinn / ruby - tokyotyrant / tree ) [CODESPLIT] def search ( type , * queries ) run_query = true run_query = queries . pop if queries . last == false raise ( ArgumentError . new ( \"pass at least one prepared query\" ) ) if queries . size < 1 t = META_TYPES [ type ] raise ( ArgumentError . new ( \"no search type #{type.inspect}\" ) ) unless t q = queries . shift . original qs = queries . collect { | qq | qq . original } pks = q . metasearch ( qs , META_TYPES [ type ] ) run_query ? lget ( pks ) : pks end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a condition [CODESPLIT] def add ( colname , operator , val , affirmative = true , no_index = false ) colname = colname . to_s val = val . to_s op = operator . is_a? ( Fixnum ) ? operator : OPERATORS [ operator ] op = op | TDBQCNEGATE unless affirmative op = op | TDBQCNOIDX if no_index @query . addcond ( colname , op , val ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process each record using the supplied block which will be passed two parameters the primary key and the value hash . [CODESPLIT] def process ( & block ) @query . proc ( ) do | key , val | r = block . call ( key , val ) r = [ r ] unless r . is_a? ( Array ) if updated_value = r . find { | e | e . is_a? ( Hash ) } val . merge! ( updated_value ) end r . inject ( 0 ) { | i , v | case v when :stop then i = i | 1 << 24 when :delete then i = i | 2 when Hash then i = i | 1 end i } end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "No comment [CODESPLIT] def []= ( k , v ) k = k . to_s ; v = v . to_s @db . put ( k , v ) || raise_error end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like #put but doesn t overwrite the value if already set . Returns true only if there no previous entry for k . [CODESPLIT] def putkeep ( k , v ) k = k . to_s ; v = v . to_s @db . putkeep ( k , v ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Appends the given string at the end of the current string value for key k . If there is no record for key k a new record will be created . [CODESPLIT] def putcat ( k , v ) k = k . to_s ; v = v . to_s @db . putcat ( k , v ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes a record from the cabinet returns the value if successful else nil . [CODESPLIT] def delete ( k ) k = k . to_s v = self [ k ] @db . out ( k ) ? v : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array of all the primary keys in the db . [CODESPLIT] def keys ( options = { } ) if @db . respond_to? :fwmkeys pref = options . fetch ( :prefix , \"\" ) @db . fwmkeys ( pref , options [ :limit ] || - 1 ) elsif @db . respond_to? :range @db . range ( \"[min,max]\" , nil ) else raise NotImplementedError , \"Database does not support keys()\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes all the entries whose keys begin with the given prefix [CODESPLIT] def delete_keys_with_prefix ( prefix ) # only ADB has the #misc method... if @db . respond_to? ( :misc ) @db . misc ( 'outlist' , @db . fwmkeys ( prefix , - 1 ) ) else @db . fwmkeys ( prefix , - 1 ) . each { | k | self . delete ( k ) } end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a list of keys returns a Hash { key = > value } of the matching entries ( in one sweep ) . [CODESPLIT] def lget ( * keys ) keys = keys . flatten . collect { | k | k . to_s } # only ADB has the #misc method... if @db . respond_to? ( :misc ) Hash [ @db . misc ( 'getlist' , keys ) ] else keys . inject ( { } ) { | h , k | v = self [ k ] ; h [ k ] = v if v ; h } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a list of keys deletes all the matching entries ( in one sweep ) . [CODESPLIT] def ldelete ( * keys ) keys = keys . flatten . collect { | k | k . to_s } # only ADB has the #misc method... if @db . respond_to? ( :misc ) @db . misc ( 'outlist' , keys ) else keys . each { | k | self . delete ( k ) } end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Increments the value stored under the given key with the given increment ( defaults to 1 ( integer )) . [CODESPLIT] def incr ( key , val = 1 ) key = key . to_s v = val . is_a? ( Fixnum ) ? @db . addint ( key , val ) : @db . adddouble ( key , val ) raise ( EdoError . new ( \"incr failed, there is probably already a string value set \" + \"for the key '#{key}'. Make sure there is no value before incrementing\" ) ) unless v v end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ". nested - container . nested - autocomplete . nested - items . nested - item . nested - content . nested - value . remove - item [CODESPLIT] def autocomplete_to_add_item ( name , f , association , source , options = { } ) new_object = f . object . send ( association ) . klass . new options [ :class ] = [ \"autocomplete add-item\" , options [ :class ] ] . compact . join \" \" options [ :data ] ||= { } options [ :data ] [ :id ] = new_object . object_id options [ :data ] [ :source ] = source options [ :data ] [ :item ] = f . fields_for ( association , new_object , child_index : options [ :data ] [ :id ] ) do | builder | render ( association . to_s . singularize + \"_item\" , f : builder ) . gsub \"\\n\" , \"\" end text_field_tag \"autocomplete_nested_content\" , nil , options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def link_to_add_item ( name f association options = {} ) options = data_attr name f association options link_to name # options end [CODESPLIT] def link_to_remove_item ( name = nil , options = { } ) name ||= \"Remove\" options [ :class ] = [ \"remove-item\" , options [ :class ] ] . compact . join \" \" link_to name , \"#\" , options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the document at the specified index [CODESPLIT] def fetch ( id ) r = nil begin r = lib . tcidbget ( @db , id ) rescue => e # if we have 'no record found' then return nil if lib . tcidbecode ( @db ) == 22 then return nil else raise_error end end return r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the document ids of the documents that matche the search expression [CODESPLIT] def search ( expression ) out_count = :: FFI :: MemoryPointer . new :pointer out_list = :: FFI :: MemoryPointer . new :pointer out_list = lib . tcidbsearch2 ( @db , expression , out_count ) count = out_count . read_int results = out_list . get_array_of_uint64 ( 0 , count ) return results end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Raises a dystopian error ( asks the db which one ) [CODESPLIT] def raise_error code = lib . tcidbecode ( @db ) msg = lib . tcidberrmsg ( code ) raise Error . new ( \"[ERROR #{code}] : #{msg}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "handling recursion - any Enumerable elements ( except String ) is being extended with the module and then symbolized [CODESPLIT] def _recurse_ ( value , & block ) if value . is_a? ( Enumerable ) && ! value . is_a? ( String ) # support for a use case without extended core Hash value . extend DeepSymbolizable unless value . class . include? ( DeepSymbolizable ) value = value . deep_symbolize ( block ) end value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes a hash of each character [CODESPLIT] def char_freq ( str ) freqs = Hash . new ( 0 ) ( 1 .. 4 ) . each do | i | str . chars . each_cons ( i ) . inject ( freqs ) do | freq , ngram | ngram = ngram . join freq [ ngram ] = freq [ ngram ] + 1 freq end end freqs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return top scoring sorted by lowest [CODESPLIT] def top ( n , scores ) scores . sort { | a , b | a [ 1 ] <=> b [ 1 ] } . map { | x | x [ 0 ] } . first ( n ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Modify the background and foreground colors and their opacities [CODESPLIT] def recolor ( bg : '#000' , fg : '#fff' , bg_opacity : \"1.0\" , fg_opacity : \"1.0\" ) OptionalDeps . require_nokogiri bg . prepend ( '#' ) unless bg . start_with? '#' fg . prepend ( '#' ) unless fg . start_with? '#' doc = Nokogiri :: XML ( self . string ) doc . css ( 'path' ) [ 0 ] [ 'fill' ] = bg # dark backdrop\r doc . css ( 'path' ) [ 1 ] [ 'fill' ] = fg # light drawing\r doc . css ( 'path' ) [ 0 ] [ 'fill-opacity' ] = bg_opacity . to_s # dark backdrop\r doc . css ( 'path' ) [ 1 ] [ 'fill-opacity' ] = fg_opacity . to_s # light drawing\r @svgstr = doc . to_xml self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A wrapper for library returning a string ( binary data potentially ) [CODESPLIT] def outlen_op ( method , * args ) args . unshift ( @db ) outlen = FFI :: MemoryPointer . new ( :int ) args << outlen out = lib . send ( method , args ) return nil if out . address == 0 out . get_bytes ( 0 , outlen . get_int ( 0 ) ) ensure outlen . free lib . tcfree ( out ) #lib.free(out) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "No comment [CODESPLIT] def []= ( k , v ) k = k . to_s ; v = v . to_s lib . abs_put ( @db , k , Rufus :: Tokyo . blen ( k ) , v , Rufus :: Tokyo . blen ( v ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like #put but doesn t overwrite the value if already set . Returns true only if there no previous entry for k . [CODESPLIT] def putkeep ( k , v ) k = k . to_s ; v = v . to_s lib . abs_putkeep ( @db , k , Rufus :: Tokyo . blen ( k ) , v , Rufus :: Tokyo . blen ( v ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Appends the given string at the end of the current string value for key k . If there is no record for key k a new record will be created . [CODESPLIT] def putcat ( k , v ) k = k . to_s ; v = v . to_s lib . abs_putcat ( @db , k , Rufus :: Tokyo . blen ( k ) , v , Rufus :: Tokyo . blen ( v ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "( The actual # [] method is provided by HashMethods [CODESPLIT] def get ( k ) k = k . to_s outlen_op ( :abs_get , k , Rufus :: Tokyo . blen ( k ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes a record from the cabinet returns the value if successful else nil . [CODESPLIT] def delete ( k ) k = k . to_s v = self [ k ] lib . abs_out ( @db , k , Rufus :: Tokyo . blen ( k ) ) ? v : nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copies the current cabinet to a new file . [CODESPLIT] def compact_copy ( target_path ) @other_db = Cabinet . new ( target_path ) self . each { | k , v | @other_db [ k ] = v } @other_db . close end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array with all the keys in the databse [CODESPLIT] def keys ( options = { } ) if @type == \"tcf\" min , max = \"min\" , \"max\" l = lib . tcfdbrange2 ( as_fixed , min , Rufus :: Tokyo . blen ( min ) , max , Rufus :: Tokyo . blen ( max ) , - 1 ) else pre = options . fetch ( :prefix , \"\" ) l = lib . abs_fwmkeys ( @db , pre , Rufus :: Tokyo . blen ( pre ) , options [ :limit ] || - 1 ) end l = Rufus :: Tokyo :: List . new ( l ) options [ :native ] ? l : l . release end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes all the entries whose keys begin with the given prefix [CODESPLIT] def delete_keys_with_prefix ( prefix ) call_misc ( 'outlist' , lib . abs_fwmkeys ( @db , prefix , Rufus :: Tokyo . blen ( prefix ) , - 1 ) ) # -1 for no limits nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a list of keys returns a Hash { key = > value } of the matching entries ( in one sweep ) . [CODESPLIT] def lget ( * keys ) keys = keys . flatten . collect { | k | k . to_s } Hash [ call_misc ( 'getlist' , Rufus :: Tokyo :: List . new ( keys ) ) ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Merges the given hash into this Cabinet ( or Tyrant ) and returns self . [CODESPLIT] def merge! ( hash ) call_misc ( 'putlist' , hash . inject ( Rufus :: Tokyo :: List . new ) { | l , ( k , v ) | l << k . to_s l << v . to_s l } ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a list of keys deletes all the matching entries ( in one sweep ) . [CODESPLIT] def ldelete ( * keys ) call_misc ( 'outlist' , Rufus :: Tokyo :: List . new ( keys . flatten . collect { | k | k . to_s } ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Increments the value stored under the given key with the given increment ( defaults to 1 ( integer )) . [CODESPLIT] def incr ( key , inc = 1 ) key = key . to_s v = inc . is_a? ( Fixnum ) ? lib . addint ( @db , key , Rufus :: Tokyo . blen ( key ) , inc ) : lib . adddouble ( @db , key , Rufus :: Tokyo . blen ( key ) , inc ) raise ( TokyoError . new ( \"incr failed, there is probably already a string value set \" + \"for the key '#{key}'. Make sure there is no value before incrementing\" ) ) if v == Rufus :: Tokyo :: INT_MIN || ( v . respond_to? ( :nan? ) && v . nan? ) v end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Triggers a defrag run ( TC > = 1 . 4 . 21 only ) [CODESPLIT] def defrag raise ( NotImplementedError . new ( \"method defrag is supported since Tokyo Cabinet 1.4.21. \" + \"your TC version doesn't support it\" ) ) unless lib . respond_to? ( :tctdbsetdfunit ) call_misc ( 'defrag' , Rufus :: Tokyo :: List . new ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "-- [CODESPLIT] def putdup ( k , v ) lib . tcbdbputdup ( as_btree , k , Rufus :: Tokyo . blen ( k ) , v , Rufus :: Tokyo . blen ( v ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is a B + Tree method only returns all the values for a given key . [CODESPLIT] def get4 ( k ) l = lib . tcbdbget4 ( as_btree , k , Rufus :: Tokyo . blen ( k ) ) Rufus :: Tokyo :: List . new ( l ) . release end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "-- def check_transaction_support raise ( TokyoError . new ( The version of Tokyo Cabinet you re using doesn t support + transactions for non - table structures . Upgrade to TC > = 1 . 4 . 13 . ) ) unless lib . respond_to? ( : tcadbtranbegin ) end ++ Wrapping tcadbmisc or tcrdbmisc ( and taking care of freeing the list_pointer ) [CODESPLIT] def call_misc ( function , list_pointer ) list_pointer = list_pointer . pointer if list_pointer . is_a? ( Rufus :: Tokyo :: List ) begin l = do_call_misc ( function , list_pointer ) raise \"function '#{function}' failed\" unless l Rufus :: Tokyo :: List . new ( l ) . release ensure Rufus :: Tokyo :: List . free ( list_pointer ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calls a lua embedded function ( http : // tokyocabinet . sourceforge . net / tyrantdoc / #luaext ) [CODESPLIT] def ext ( func_name , key = '' , value = '' , opts = { } ) k = key . to_s v = value . to_s outlen_op ( :tcrdbext , func_name . to_s , compute_ext_opts ( opts ) , k , Rufus :: Tokyo . blen ( k ) , v , Rufus :: Tokyo . blen ( v ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates an empty instance of a Tokyo Cabinet in - memory map [CODESPLIT] def []= ( k , v ) clib . tcmapput ( pointer , k , Rufus :: Tokyo :: blen ( k ) , v , Rufus :: Tokyo :: blen ( v ) ) v end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes an entry [CODESPLIT] def delete ( k ) v = self [ k ] return nil unless v clib . tcmapout ( pointer_or_raise , k , Rufus :: Tokyo :: blen ( k ) ) || raise ( \"failed to remove key '#{k}'\" ) v end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array of all the keys in the map [CODESPLIT] def keys clib . tcmapiterinit ( pointer_or_raise ) a = [ ] klen = FFI :: MemoryPointer . new ( :int ) loop do k = clib . tcmapiternext ( @pointer , klen ) break if k . address == 0 a << k . get_bytes ( 0 , klen . get_int ( 0 ) ) end return a ensure klen . free end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The put operation . [CODESPLIT] def []= ( a , b , c = nil ) i , s = c . nil? ? [ a , b ] : [ [ a , b ] , c ] range = if i . is_a? ( Range ) i elsif i . is_a? ( Array ) start , count = i ( start .. start + count - 1 ) else [ i ] end range = norm ( range ) values = s . is_a? ( Array ) ? s : [ s ] # not \"values = Array(s)\" range . each_with_index do | offset , index | val = values [ index ] if val clib . tclistover ( @pointer , offset , val , Rufus :: Tokyo . blen ( val ) ) else outlen_op ( :tclistremove , values . size ) end end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The equivalent of Ruby Array# [] [CODESPLIT] def [] ( i , count = nil ) return nil if ( count != nil ) && count < 1 len = self . size range = if count . nil? i . is_a? ( Range ) ? i : [ i ] else ( i .. i + count - 1 ) end r = norm ( range ) . collect { | ii | outlen_op ( :tclistval , ii ) } range . first == range . last ? r . first : r end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Makes sure this offset / range fits the size of the list [CODESPLIT] def norm ( i ) l = self . length case i when Range then ( ( i . first % l ) .. ( i . last % l ) ) when Array then [ i . first % l ] else i % l end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets an index on a column of the table . [CODESPLIT] def set_index ( column_name , * types ) column_name = column_name == :pk ? '' : column_name . to_s ii = types . inject ( 0 ) { | i , t | i = i | INDEX_TYPES [ t ] ; i } lib . tab_setindex ( @db , column_name , ii ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inserts a record in the table db [CODESPLIT] def []= ( pk , h_or_a ) pk = pk . to_s h_or_a = Rufus :: Tokyo . h_or_a_to_s ( h_or_a ) m = Rufus :: Tokyo :: Map [ h_or_a ] r = lib . tab_put ( @db , pk , Rufus :: Tokyo . blen ( pk ) , m . pointer ) m . free r || raise_error # raising potential error after freeing map h_or_a end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Removes an entry in the table [CODESPLIT] def delete ( k ) k = k . to_s v = self [ k ] return nil unless v libcall ( :tab_out , k , Rufus :: Tokyo . blen ( k ) ) v end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an array of all the primary keys in the table [CODESPLIT] def keys ( options = { } ) pre = options . fetch ( :prefix , \"\" ) l = lib . tab_fwmkeys ( @db , pre , Rufus :: Tokyo . blen ( pre ) , options [ :limit ] || - 1 ) l = Rufus :: Tokyo :: List . new ( l ) options [ :native ] ? l : l . release end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "No misc methods for the table library so this lget is equivalent to calling get for each key . Hoping later versions of TC will provide a mget method . [CODESPLIT] def lget ( * keys ) keys . flatten . inject ( { } ) { | h , k | k = k . to_s v = self [ k ] h [ k ] = v if v h } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepares and runs a query returns a ResultSet instance ( takes care of freeing the query structure ) [CODESPLIT] def do_query ( & block ) q = prepare_query ( block ) rs = q . run return rs ensure q && q . free end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepares and runs a query returns an array of hashes ( all Ruby ) ( takes care of freeing the query and the result set structures ) [CODESPLIT] def query ( & block ) rs = do_query ( block ) a = rs . to_a return a ensure rs && rs . free end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepares a query and then runs it and deletes all the results . [CODESPLIT] def query_delete ( & block ) q = prepare_query ( block ) rs = q . delete return rs ensure q && q . free end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Prepares a query and then runs it and deletes all the results . [CODESPLIT] def query_count ( & block ) q = prepare_query { | q | q . pk_only # improve efficiency, since we have to do the query } q . count ensure q . free if q end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A #search a la ruby - tokyotyrant ( http : // github . com / actsasflinn / ruby - tokyotyrant / tree ) [CODESPLIT] def search ( type , * queries ) run_query = true run_query = queries . pop if queries . last == false raise ( ArgumentError . new ( \"pass at least one prepared query\" ) ) if queries . size < 1 raise ( ArgumentError . new ( \"pass instances of Rufus::Tokyo::TableQuery only\" ) ) if queries . find { | q | q . class != TableQuery } t = META_TYPES [ type ] raise ( ArgumentError . new ( \"no search type #{type.inspect}\" ) ) unless t qs = FFI :: MemoryPointer . new ( :pointer , queries . size ) qs . write_array_of_pointer ( queries . collect { | q | q . pointer } ) r = lib . tab_metasearch ( qs , queries . size , t ) qs . free pks = Rufus :: Tokyo :: List . new ( r ) . release run_query ? lget ( pks ) : pks end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the value ( as a Ruby Hash ) else nil [CODESPLIT] def get ( k ) k = k . to_s m = lib . tab_get ( @db , k , Rufus :: Tokyo . blen ( k ) ) return nil if m . address == 0 Map . to_h ( m ) # which frees the map end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Obviously something got wrong let s ask the db about it and raise a TokyoError [CODESPLIT] def raise_error err_code = lib . tab_ecode ( @db ) err_msg = lib . tab_errmsg ( err_code ) raise TokyoError . new ( \"(err #{err_code}) #{err_msg}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process each record using the supplied block which will be passed two parameters the primary key and the value hash . [CODESPLIT] def process ( & block ) callback = lambda do | pk , pklen , map , opt_param | key = pk . read_string ( pklen ) val = Rufus :: Tokyo :: Map . new ( map ) . to_h r = block . call ( key , val ) r = [ r ] unless r . is_a? ( Array ) if updated_value = r . find { | e | e . is_a? ( Hash ) } Rufus :: Tokyo :: Map . new ( map ) . merge! ( updated_value ) end r . inject ( 0 ) { | i , v | case v when :stop then i = i | 1 << 24 when :delete then i = i | 2 when Hash then i = i | 1 end i } end lib . qry_proc ( @query , callback , nil ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The classical each [CODESPLIT] def each ( 0 .. size - 1 ) . each do | i | pk = @list [ i ] if @opts [ :pk_only ] yield ( pk ) else val = @table [ pk ] val [ :pk ] = pk unless @opts [ :no_pk ] yield ( val ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Find the icon possibly without the extension . [CODESPLIT] def find ( icon ) str = icon . to_s . downcase file = DB . files [ str ] || DB . files [ str . sub ( / \\. / , '' ) ] || not_found ( str , icon ) Icon . new ( file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get all colums for a given table . [CODESPLIT] def get_columns ( table_name ) columns_arr = [ ] pst = @db . prepare \"SELECT * FROM #{table_name} LIMIT 6\" pst . columns . each do | c | columns_arr . push ( c ) end columns_arr end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If the column type is nominal return true . [CODESPLIT] def is_numeric ( table_name , column_name ) if @db . execute ( \"SELECT #{column_name} from #{table_name} LIMIT 1\" ) . first . first . is_a? Numeric return true else return false end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If valid option was provided in convert method [CODESPLIT] def deal_with_valid_option ( temp_tables , temp_columns , temp_column_types , res ) if ! temp_tables . empty? check_given_tables_validity ( temp_tables ) temp_tables . each do | t | res << convert_table ( t ) end elsif ! temp_columns . keys . empty? check_given_columns_validity ( temp_columns ) res << convert_from_columns_hash ( temp_columns ) elsif ! temp_column_types . empty? check_given_columns_validity ( temp_column_types ) res << convert_from_column_types_hash ( temp_column_types ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This allows us to simplify the case where we want to have a context which contains one or more let statements [CODESPLIT] def let_context ( * args , & block ) context_string , hash = case args . map ( :class ) when [ String , Hash ] then [ \"#{args[0]} #{args[1]}\" , args [ 1 ] ] when [ Hash ] then [ args [ 0 ] . inspect , args [ 0 ] ] end context ( context_string ) do hash . each { | var , value | let ( var ) { value } } instance_eval ( block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allows you to simply specify that the subject should raise an exception Takes no arguments or arguments of an exception class a string or both . [CODESPLIT] def subject_should_raise ( * args ) error , message = args it_string = \"subject should raise #{error}\" it_string += \" (#{message.inspect})\" if message it it_string do expect { subject } . to raise_error error , message end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allows you to simply specify that the subject should not raise an exception . Takes no arguments or arguments of an exception class a string or both . [CODESPLIT] def subject_should_not_raise ( * args ) error , message = args it_string = \"subject should not raise #{error}\" it_string += \" (#{message.inspect})\" if message it it_string do expect { subject } . not_to raise_error error , message end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Application [CODESPLIT] def xmessage_rule_key_mapping @rule_key_mapping ||= { number : { one : 'singular' , few : 'few' , many : 'many' , other : 'plural' } , gender : { male : 'male' , female : 'female' , neutral : 'neutral' , other : 'other' , } , date : { future : 'future' , present : 'present' , past : 'past' } } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Logs a user in . [CODESPLIT] def login ( user , options = { } ) options [ :scope ] ||= Janus . scope_for ( user ) set_user ( user , options ) Janus :: Manager . run_callbacks ( :login , user , self , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Logs a user out from the given scopes or from all scopes at once if no scope is defined . If no scope is left after logout then the whole session will be resetted . [CODESPLIT] def logout ( * scopes ) scopes = janus_sessions . keys if scopes . empty? scopes . each do | scope | _user = user ( scope ) unset_user ( scope ) Janus :: Manager . run_callbacks ( :logout , _user , self , :scope => scope ) end request . reset_session if janus_sessions . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Manually sets a user without going throught the whole login or authenticate process . [CODESPLIT] def set_user ( user , options = { } ) scope = options [ :scope ] || Janus . scope_for ( user ) janus_sessions [ scope . to_s ] = { 'user_class' => user . class . name , 'user_id' => user . id } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Manually removes the user without going throught the whole logout process . [CODESPLIT] def unset_user ( scope ) janus_sessions . delete ( scope . to_s ) @users . delete ( scope . to_sym ) unless @users . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the currently connected user . [CODESPLIT] def user ( scope ) scope = scope . to_sym @users ||= { } if authenticated? ( scope ) if @users [ scope ] . nil? begin @users [ scope ] = user_class ( scope ) . find ( session ( scope ) [ 'user_id' ] ) rescue ActiveRecord :: RecordNotFound unset_user ( scope ) else Janus :: Manager . run_callbacks ( :fetch , @users [ scope ] , self , :scope => scope ) end end @users [ scope ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "namespace of each cache key [CODESPLIT] def namespace return '#' if Tml . config . disabled? @namespace || Tml . config . cache [ :namespace ] || Tml . config . application [ :key ] [ 0 .. 5 ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Pulls cache version from CDN [CODESPLIT] def extract_version ( app , version = nil ) if version Tml . cache . version . set ( version . to_s ) else version_data = app . api_client . get_from_cdn ( 'version' , { t : Time . now . to_i } , { uncompressed : true } ) unless version_data Tml . logger . debug ( 'No releases have been generated yet. Please visit your Dashboard and publish translations.' ) return end Tml . cache . version . set ( version_data [ 'version' ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Warms up cache from CDN or local files [CODESPLIT] def warmup ( version = nil , cache_path = nil ) if cache_path . nil? warmup_from_cdn ( version ) else warmup_from_files ( version , cache_path ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Warms up cache from local files [CODESPLIT] def warmup_from_files ( version = nil , cache_path = nil ) t0 = Time . now Tml . logger = Logger . new ( STDOUT ) Tml . logger . debug ( 'Starting cache warmup from local files...' ) version ||= Tml . config . cache [ :version ] cache_path ||= Tml . config . cache [ :path ] cache_path = \"#{cache_path}/#{version}\" Tml . cache . version . set ( version . to_s ) Tml . logger . debug ( \"Warming Up Version: #{Tml.cache.version}\" ) application = JSON . parse ( File . read ( \"#{cache_path}/application.json\" ) ) Tml . cache . store ( Tml :: Application . cache_key , application ) sources = JSON . parse ( File . read ( \"#{cache_path}/sources.json\" ) ) application [ 'languages' ] . each do | lang | locale = lang [ 'locale' ] language = JSON . parse ( File . read ( \"#{cache_path}/#{locale}/language.json\" ) ) Tml . cache . store ( Tml :: Language . cache_key ( locale ) , language ) sources . each do | src | source = JSON . parse ( File . read ( \"#{cache_path}/#{locale}/sources/#{src}.json\" ) ) Tml . cache . store ( Tml :: Source . cache_key ( locale , src ) , source ) end end t1 = Time . now Tml . logger . debug ( \"Cache warmup took #{t1-t0}s\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Warms up cache from CDN [CODESPLIT] def warmup_from_cdn ( version = nil ) t0 = Time . now Tml . logger = Logger . new ( STDOUT ) Tml . logger . debug ( 'Starting cache warmup from CDN...' ) app = Tml :: Application . new ( key : Tml . config . application [ :key ] , cdn_host : Tml . config . application [ :cdn_host ] ) extract_version ( app , version ) Tml . logger . debug ( \"Warming Up Version: #{Tml.cache.version}\" ) application = app . api_client . get_from_cdn ( 'application' , { t : Time . now . to_i } ) Tml . cache . store ( Tml :: Application . cache_key , application ) sources = app . api_client . get_from_cdn ( 'sources' , { t : Time . now . to_i } , { uncompressed : true } ) application [ 'languages' ] . each do | lang | locale = lang [ 'locale' ] language = app . api_client . get_from_cdn ( \"#{locale}/language\" , { t : Time . now . to_i } ) Tml . cache . store ( Tml :: Language . cache_key ( locale ) , language ) sources . each do | src | source = app . api_client . get_from_cdn ( \"#{locale}/sources/#{src}\" , { t : Time . now . to_i } ) Tml . cache . store ( Tml :: Source . cache_key ( locale , src ) , source ) end end t1 = Time . now Tml . logger . debug ( \"Cache warmup took #{t1-t0}s\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "default cache path [CODESPLIT] def default_cache_path @cache_path ||= begin path = Tml . config . cache [ :path ] path ||= 'config/tml' FileUtils . mkdir_p ( path ) FileUtils . chmod ( 0777 , path ) path end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "downloads cache from the CDN [CODESPLIT] def download ( cache_path = default_cache_path , version = nil ) t0 = Time . now Tml . logger = Logger . new ( STDOUT ) Tml . logger . debug ( 'Starting cache download...' ) app = Tml :: Application . new ( key : Tml . config . application [ :key ] , cdn_host : Tml . config . application [ :cdn_host ] ) extract_version ( app , version ) Tml . logger . debug ( \"Downloading Version: #{Tml.cache.version}\" ) archive_name = \"#{Tml.cache.version}.tar.gz\" path = \"#{cache_path}/#{archive_name}\" url = \"#{app.cdn_host}/#{Tml.config.application[:key]}/#{archive_name}\" Tml . logger . debug ( \"Downloading cache file: #{url}\" ) open ( path , 'wb' ) do | file | file << open ( url ) . read end Tml . logger . debug ( 'Extracting cache file...' ) version_path = \"#{cache_path}/#{Tml.cache.version}\" Tml :: Utils . untar ( Tml :: Utils . ungzip ( File . new ( path ) ) , version_path ) Tml . logger . debug ( \"Cache has been stored in #{version_path}\" ) File . unlink ( path ) begin current_path = 'current' FileUtils . chdir ( cache_path ) FileUtils . rm ( current_path ) if File . exist? ( current_path ) FileUtils . ln_s ( Tml . cache . version . to_s , current_path ) Tml . logger . debug ( \"The new version #{Tml.cache.version} has been marked as current\" ) rescue Exception => ex Tml . logger . debug ( \"Could not generate current symlink to the cache path: #{ex.message}\" ) end t1 = Time . now Tml . logger . debug ( \"Cache download took #{t1-t0}s\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "remove extensions [CODESPLIT] def strip_extensions ( data ) if data . is_a? ( Hash ) data = data . dup data . delete ( 'extensions' ) return data end if data . is_a? ( String ) and data . match ( / \\{ / ) data = JSON . parse ( data ) data . delete ( 'extensions' ) data = data . to_json end data end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Arguments : * file * name * type * flags * mode * env or : ** file ** ** opts ** . * opts * must be a * :: Hash * with keys like above excluded * file * . [CODESPLIT] def each key = nil , val = nil , & exe cursor { | c | c . each key , val , exe } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Block Options [CODESPLIT] def block_option ( key , lookup = true ) if lookup block_options_queue . reverse . each do | options | value = options [ key . to_s ] || options [ key . to_sym ] return value if value end return nil end block_options [ key ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "shortcut to say [CODESPLIT] def say ( message , color = nil ) @shell ||= Thor :: Shell :: Basic . new @shell . say message , color end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "validate that current cache version hasn t expired [CODESPLIT] def validate_cache_version ( version ) # if cache version is hardcoded, use it if Tml . config . cache [ :version ] return Tml . config . cache [ :version ] end return version unless version . is_a? ( Hash ) return 'undefined' unless version [ 't' ] . is_a? ( Numeric ) return version [ 'version' ] if cache . read_only? # if version check interval is disabled, don't try to check for the new # cache version on the CDN if version_check_interval == - 1 Tml . logger . debug ( 'Cache version check is disabled' ) return version [ 'version' ] end expires_at = version [ 't' ] + version_check_interval if expires_at < Time . now . to_i Tml . logger . debug ( 'Cache version is outdated, needs refresh' ) return 'undefined' end delta = expires_at - Time . now . to_i Tml . logger . debug ( \"Cache version is up to date, expires in #{delta}s\" ) version [ 'version' ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fetches the version from the cache [CODESPLIT] def fetch self . version = begin ver = cache . fetch ( CACHE_VERSION_KEY ) do { 'version' => Tml . config . cache [ :version ] || 'undefined' , 't' => cache_timestamp } end validate_cache_version ( ver ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Opens a Database . see SBDB :: DB SBDB :: Btree SBDB :: Hash SBDB :: Recno SBDB :: Queue [CODESPLIT] def open type , file , * ps , & exe ps . push :: Hash . new unless :: Hash === ps . last ps . last [ :env ] = self ( type || SBDB :: Unkown ) . new file , ps , exe end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the DB like open but if it s already opened it returns the old instance . If you use this never use close . It s possible somebody else use it too . The Databases which are opened will close if the Environment will close . [CODESPLIT] def [] file , * ps , & exe opts = :: Hash === ps . last ? ps . pop : { } opts [ :env ] = self name , type , flg = ps [ 0 ] || opts [ :name ] , ps [ 1 ] || opts [ :type ] , ps [ 2 ] || opts [ :flags ] ps . push opts @dbs [ [ file , name , flg | CREATE ] ] ||= ( type || SBDB :: Unknown ) . new file , ps , exe end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs authentication strategies to log a user in . [CODESPLIT] def run_strategies ( scope ) Janus :: Manager . strategies . each { | name | break if run_strategy ( name , scope ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs a given strategy and returns true if it succeeded . [CODESPLIT] def run_strategy ( name , scope ) strategy = \"Janus::Strategies::#{name.to_s.camelize}\" . constantize . new ( scope , self ) if strategy . valid? strategy . authenticate! if strategy . success? send ( strategy . auth_method , strategy . user , :scope => scope ) Janus :: Manager . run_callbacks ( :authenticate , strategy . user , self , :scope => scope ) end end strategy . success? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "run script with params [CODESPLIT] def perform ( script ) export_variables = @params . reverse_merge ( \"PARADUCT_JOB_ID\" => @job_id , \"PARADUCT_JOB_NAME\" => job_name ) variable_string = export_variables . map { | key , value | %(export #{key}=\"#{value}\";) } . join ( \" \" ) Array . wrap ( script ) . inject ( \"\" ) do | stdout , command | stdout << run_command ( \"#{variable_string} #{command}\" ) stdout end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "observer callback [CODESPLIT] def update ( event , target ) case event when :user_deleted @users = @users . delete_if { | element | element == target } target . delete_observer ( self ) else raise ArgumentError . new ( event ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Collects mimes and return the response for the negotiated format . Returns nil if : not_acceptable was sent to the client . [CODESPLIT] def retrieve_response_from_mimes ( mimes , & block ) responder = ActionController :: MimeResponds :: Responder . new ( self ) mimes = collect_mimes_from_class_level if mimes . empty? mimes . each { | mime | responder . send ( mime ) } block . call ( responder ) if block_given? if format = responder . negotiate_mime self . response . template . template_format = format . to_sym self . response . content_type = format . to_s self . formats = [ format . to_sym ] responder . response_for ( format ) || proc { default_render } else head :not_acceptable nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "shameless steal from forem git : // github . com / radar / forem . git [CODESPLIT] def add_abstractor_user_method current_user_helper = options [ \"current-user-helper\" ] . presence || ask ( \"What is the current_user helper called in your app? [current_user]\" ) . presence || 'current_user if defined?(current_user)' puts \"Defining abstractor_user method inside ApplicationController...\" abstractor_user_method = %Q{\n  def abstractor_user\n    #{current_user_helper}\n  end\n  helper_method :abstractor_user\n} inject_into_file ( \"#{Rails.root}/app/controllers/application_controller.rb\" , abstractor_user_method , :after => \"ActionController::Base\\n\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the common behavior for navigation requests like : html : iphone and so forth . [CODESPLIT] def navigation_behavior ( error ) if get? raise error elsif has_errors? && default_action render :action => default_action else redirect_to resource_location end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the common behavior for API requests like : xml and : json . [CODESPLIT] def api_behavior ( error ) if get? display resource elsif has_errors? display resource . errors , :status => :unprocessable_entity elsif post? display resource , :status => :created , :location => resource_location else head :ok end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "observer callback [CODESPLIT] def update ( event , target ) case event when :document_removed , :document_deleted @documents = @documents . delete_if { | element | element == target } target . delete_observer ( self ) when :document_added @documents . push target target . add_observer ( self ) when :folder_deleted @folders = @folders . delete_if { | element | element == target } else raise ArgumentError . new ( event ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Format data as hex in various styles . [CODESPLIT] def print_hex ( data , chunk_index , cols = 80 ) case hex_style when 'lower' , 'lowercase' # encode to lowercase hex with no newlines print Sixword :: Hex . encode ( data ) when 'finger' , 'fingerprint' # encode to GPG fingerprint like hex with newlines newlines_every = cols / 5 if chunk_index != 0 if chunk_index % newlines_every == 0 print \"\\n\" else print ' ' end end print Sixword :: Hex . encode_fingerprint ( data ) when 'colon' , 'colons' # encode to SSL/SSH fingerprint like hex with colons print ':' unless chunk_index == 0 print Sixword :: Hex . encode_colons ( data ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run the encoding / decoding operation printing the result to stdout . [CODESPLIT] def run! if encoding? do_encode! do | encoded | puts encoded end else chunk_index = 0 do_decode! do | decoded | if hex_style print_hex ( decoded , chunk_index ) chunk_index += 1 else print decoded end end # add trailing newline for hex output puts if hex_style end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Yield data 6 words at a time until EOF [CODESPLIT] def read_input_by_6_words word_arr = [ ] while true line = stream . gets if line . nil? break # EOF end line . scan ( / \\S / ) do | word | word_arr << word # return the array if we have accumulated 6 words if word_arr . length == 6 yield word_arr word_arr . clear end end end # yield whatever we have left, if anything if ! word_arr . empty? yield word_arr end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialize a new QueryBuilder for + index_name + . [CODESPLIT] def select ( query , filters ) where , * bind_values = conditions ( query , filters ) [ [ from ( filters ) , where , order_by ( filters ) , limits ( filters ) ] . join ( \" \" ) , bind_values ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build a SphinxQL query to update the record identified by + id + with the given attributes . [CODESPLIT] def update ( id , attributes ) set_attrs , * bind_values = update_attributes ( attributes ) [ [ \"UPDATE #{@index_name} SET\" , set_attrs , \"WHERE id = ?\" ] . join ( \" \" ) , bind_values . push ( id ) ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute a single read query . [CODESPLIT] def query ( sql , * bind_values ) @pool . acquire { | conn | conn . query ( sql , bind_values ) . first } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the name for this worker class if not already set ( i . e . if it s an anonymous class ) . The first time the name for the worker is set it becomes registered with MixinRegistry . After that attempting to change the worker class will raise ArgumentError . [CODESPLIT] def set_worker_name ( name ) if @worker_name raise ArgumentError , \"cannot change worker name\" else if name and ! name . empty? @worker_name = name . to_sym Woodhouse :: MixinRegistry . register self end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "You can dispatch a job + baz + on class + FooBar + by calling FooBar . async_baz . [CODESPLIT] def method_missing ( method , * args , & block ) if method . to_s =~ / / if instance_methods ( false ) . detect { | meth | meth . to_s == $1 } Woodhouse . dispatch ( @worker_name , $1 , args . first ) else super end else super end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a Node to this layout . If + node + is a Symbol a Node will be automatically created with that name . [CODESPLIT] def add_node ( node ) if node . respond_to? ( :to_sym ) node = Woodhouse :: Layout :: Node . new ( node . to_sym ) end expect_arg :node , Woodhouse :: Layout :: Node , node @nodes << node node end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Looks up a Node by name and returns it . [CODESPLIT] def node ( name ) name = name . to_sym @nodes . detect { | node | node . name == name } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a frozen copy of this Layout and all of its child Node and Worker objects . Woodhouse :: Server always takes a frozen copy of the layout it is given . It is thus safe to modify the same layout subsequently and the changes only take effect when the layout is passed to the server again and Woodhouse :: Server#reload is called . [CODESPLIT] def frozen_clone clone . tap do | cloned | cloned . nodes = @nodes . map { | node | node . frozen_clone } . freeze cloned . freeze end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If this Deferrable succeeds ensure that the arguments passed to + Deferrable#succeed + meet certain criteria ( specified by passing a predicate as a block ) . If they do subsequently defined callbacks will fire as normal receiving the same arguments ; if they do not this Deferrable will fail instead calling its errbacks with a { GuardFailed } exception . [CODESPLIT] def guard ( reason = nil , & block ) raise ArgumentError , 'must be called with a block' unless block_given? callback do | * callback_args | begin unless block . call ( callback_args ) raise :: DeferrableGratification :: GuardFailed . new ( reason , callback_args ) end rescue => exception fail ( exception ) end end self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "生成计划任务 [CODESPLIT] def generate_tasks tasks = [ ] Plan . transaction do assignables . each do | a | tasks << generate_task_for_assignable ( a ) end end update_attributes ( last_task_created_at : Time . now ) tasks end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Note : must be equal? to AUTO ( i . e . same object ) not just == builds a character filling required attributes default attributes for this type of character and the attributes given . [CODESPLIT] def build ( attribute_list = nil ) @seq = ( story . counter [ @model ] += 1 ) lists = [ required_attributes , default_attribute_lists , attribute_list ] lists . prepend [ :created_at ] if @ar . has_attribute? ( :created_at ) attribute_list = lists . map { | al | canonical ( al ) } . inject ( :merge ) log ( :building , attribute_list ) set_attributes ( attribute_list ) unless @ar . valid? attribute_list = canonical ( @ar . errors . map { | attr , _ | attr } ) log ( :fixing_errors , attribute_list ) set_attributes ( attribute_list ) end yield @ar if block_given? log ( :final_value , @ar ) @ar end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts an attribute_list to a single Hash ; some of the values may be set to AUTO . [CODESPLIT] def canonical ( attribute_list ) case attribute_list when nil then { } when Hash then attribute_list when Array attribute_list . map do | attributes | case attributes when Symbol { attributes => AUTO } when Hash attributes else raise \"Unexpected attributes #{attributes}\" end end . inject ( { } , :merge ) else raise \"Unexpected attribute_list #{attribute_list}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a character with the given attributes [CODESPLIT] def imagine ( character_or_model , attributes = nil ) character = to_character ( character_or_model ) prev , @building = @building , [ ] # because method might be re-entrant CharacterBuilder . new ( character ) . build ( attributes ) do | ar | ar . save! # While errors on records associated with :has_many will prevent records # from being saved, they won't for :belongs_to, so: @building . each do | built | raise ActiveRecord :: RecordInvalid , built unless built . persisted? || built . valid? end Scheherazade . log ( :saving , character , ar ) handle_callbacks ( @building ) end ensure @built . concat ( @building ) @building = prev end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allows one to temporarily override the current characters while the given block executes [CODESPLIT] def with ( temp_current ) keys = temp_current . keys . map { | k | to_character ( k ) } previous_values = current . values_at ( keys ) current . merge! ( Hash [ keys . zip ( temp_current . values ) ] ) yield ensure current . merge! ( Hash [ keys . zip ( previous_values ) ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / achievements GET / achievements . xml [CODESPLIT] def index @achievements = Achievement . all respond_to do | format | format . html # index.html.erb format . xml { render :xml => @achievements } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / achievements / 1 GET / achievements / 1 . xml [CODESPLIT] def show @achievement = Achievement . find ( params [ :id ] ) @conditions = @achievement . achievement_conditions respond_to do | format | format . html # show.html.erb format . xml { render :xml => @achievement } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / achievements / new GET / achievements / new . xml [CODESPLIT] def new @achievement = Achievement . new respond_to do | format | format . html # new.html.erb format . xml { render :xml => @achievement } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST / achievements POST / achievements . xml [CODESPLIT] def create @achievement = Achievement . new ( params [ :triumph_achievement ] ) @achievement . observe_class . singularize . downcase! if @achievement . save achievement_condition = AchievementCondition . new ( params [ :achievement_condition ] ) achievement_condition . achievement_id = @achievement . id if achievement_condition . save redirect_to ( @achievement , :notice => 'Achievement was successfully created.' ) else flash [ :error ] = \"Failed to save achievement conditions\" end else render :action => \"new\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "PUT / achievements / 1 PUT / achievements / 1 . xml [CODESPLIT] def update @achievement = Achievement . find ( params [ :id ] ) @achievement . observe_class . downcase! respond_to do | format | if @achievement . update_attributes ( params [ :triumph_achievement ] ) format . html { redirect_to ( @achievement , :notice => 'Achievement was successfully updated.' ) } format . xml { head :ok } else format . html { render :action => \"edit\" } format . xml { render :xml => @achievement . errors , :status => :unprocessable_entity } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "DELETE / achievements / 1 DELETE / achievements / 1 . xml [CODESPLIT] def destroy @achievement = Achievement . find ( params [ :id ] ) @achievement . destroy respond_to do | format | format . html { redirect_to ( triumph_achievements_url ) } format . xml { head :ok } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "提醒任务执行者，任务即将到期，并且修改任务下次提醒时间。 如果 next_reminding_at 返回 nil ，则表示该任务不再需要提醒。 [CODESPLIT] def remind Task . transaction do assignee . remind_of_expiring_task ( self ) if assignee . respond_to? ( :remind_of_expiring_task ) update_attributes! ( reminding_at : next_reminding_at ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a Deferrable which immediately fails with an exception . [CODESPLIT] def failure ( exception_class_or_message , message_or_nil = nil ) blank . tap do | d | d . fail ( case exception_class_or_message when Exception raise ArgumentError , \"can't specify both exception and message\" if message_or_nil exception_class_or_message when Class exception_class_or_message . new ( message_or_nil ) else RuntimeError . new ( exception_class_or_message . to_s ) end ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Function to check that the file size isn t excesive . [CODESPLIT] def file_length if self . audio . is_a? ( File ) && self . audio . size > MAX_FILE_SIZE self . errors . add :audio , \"It's length is excesive. #{MAX_FILE_SIZE} is the limit.\" return false end return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Function to call API passing a payload [CODESPLIT] def api_call method , payload raise ArgumentError , \"API method not specified.\" if method . blank? payload ||= { } res = @conn . post method . to_s , payload raise Faraday :: Error , \"Wrong response: #{res.inspect}\" if ( res . status != 200 ) return res end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a a batch search on the index . [CODESPLIT] def multi_search ( queries ) unless queries . kind_of? ( Hash ) raise ArgumentError , \"Argument must be a Hash of named queries (#{queries.class} given)\" end stmts = [ ] bind_values = [ ] queries . each do | key , args | str , * values = @builder . select ( extract_query_data ( args ) ) stmts . push ( str , \"SHOW META\" ) bind_values . push ( values ) end rs = @conn . multi_query ( stmts . join ( \";\\n\" ) , bind_values ) Hash [ ] . tap do | result | queries . keys . each do | key | records , meta = rs . shift , rs . shift result [ key ] = meta_to_hash ( meta ) . tap do | r | r [ :records ] = records . map { | hash | hash . inject ( { } ) { | o , ( k , v ) | o . merge! ( k . to_sym => v ) } } end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Usage hints https : // github . com / google / google - api - ruby - client / issues / 360 get multiple users if you don t want the defaults { max_results : 10 order_by : email } you must override ( a nil disables the option ) [CODESPLIT] def users_list ( attributes : { } ) defaults = { max_results : 10 , order_by : 'email' } filters = defaults . merge ( attributes ) response = service . list_users ( filters ) { response : response , attributes : filters , command : :users_list } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Accepts a symbol that will define the inherited type of Address . Defaults to the parent class . [CODESPLIT] def has_whereabouts klass = :address , * args options = args . extract_options! # extend Address with class name if not defined. unless klass == :address || Object . const_defined? ( klass . to_s . camelize ) create_address_class ( klass . to_s . camelize ) end # Set the has_one relationship and accepts_nested_attributes_for.   has_one klass , :as => :addressable , :dependent => :destroy accepts_nested_attributes_for klass # Define a singleton on the class that returns an array # that includes the address fields to validate presence of  # or an empty array if options [ :validate ] && options [ :validate ] . is_a? ( Array ) validators = options [ :validate ] set_validators ( klass , validators ) else validators = [ ] end define_singleton_method validate_singleton_for ( klass ) do validators end # Check for geocode in options and confirm geocoder is defined. # Also defines a singleton to return a boolean about geocoding. if options [ :geocode ] && options [ :geocode ] == true && defined? ( Geocoder ) geocode = true set_geocoding ( klass ) else geocode = false end define_singleton_method geocode_singleton_for ( klass ) do geocode end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets validates_presence_of fields for the Address based on the singleton method created on the Address addressable_type class . [CODESPLIT] def set_validators klass , fields = [ ] _single = validate_singleton_for ( klass ) klass . to_s . camelize . constantize . class_eval do fields . each do | f | validates_presence_of f , :if => lambda { | a | a . addressable_type . constantize . send ( _single ) . include? ( f ) } end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Geocode the address using Address#geocode_address if the geocode_singleton is true and the record is either new or has been updated . [CODESPLIT] def set_geocoding klass _single = geocode_singleton_for ( klass ) klass . to_s . camelize . constantize . class_eval do geocoded_by :geocode_address after_validation :geocode , :if => lambda { | a | a . addressable_type . constantize . send ( _single ) && ( a . new_record? || a . changed? ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate a new class using Address as the superclass . Accepts a string defining the inherited type . [CODESPLIT] def create_address_class ( class_name , & block ) klass = Class . new Address , block Object . const_set class_name , klass end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Start the event loop for handling messages off the queue [CODESPLIT] def event_loop Qwirk . logger . debug \"#{self}: Starting receive loop\" @start_worker_time = Time . now until @stopped || ( config . stopped? && @impl . ready_to_stop? ) Qwirk . logger . debug \"#{self}: Waiting for read\" @start_read_time = Time . now msg = @impl . receive_message if msg @start_processing_time = Time . now Qwirk . logger . debug { \"#{self}: Done waiting for read in #{@start_processing_time - @start_read_time} seconds\" } delta = config . timer . measure do @processing_mutex . synchronize do on_message ( msg ) @impl . acknowledge_message ( msg ) end end Qwirk . logger . info { \"#{self}::on_message (#{'%.1f' % delta}ms)\" } if self . config . log_times Qwirk . logger . flush if Qwirk . logger . respond_to? ( :flush ) end end Qwirk . logger . info \"#{self}: Exiting\" rescue Exception => e @status = \"Terminated: #{e.message}\" Qwirk . logger . error \"#{self}: Exception, thread terminating: #{e.message}\\n\\t#{e.backtrace.join(\"\\n\\t\")}\" ensure @status = 'Stopped' Qwirk . logger . flush if Qwirk . logger . respond_to? ( :flush ) config . worker_stopped ( self ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method is replaced for Rails 3 compatibility . All I do is add the condition when the field is a hash that converts the value to hstore format . IMHO this should be delegated to the column so it won t be necessary to rewrite all this method . [CODESPLIT] def arel_attributes_values ( include_primary_key = true , include_readonly_attributes = true , attribute_names = @attributes . keys ) attrs = { } attribute_names . each do | name | if ( column = column_for_attribute ( name ) ) && ( include_primary_key || ! column . primary ) if include_readonly_attributes || ( ! include_readonly_attributes && ! self . class . readonly_attributes . include? ( name ) ) value = read_attribute ( name ) if self . class . columns_hash [ name ] . type == :hstore && value && value . is_a? ( Hash ) value = value . to_hstore # Done! elsif value && self . class . serialized_attributes . has_key? ( name ) && ( value . acts_like? ( :date ) || value . acts_like? ( :time ) || value . is_a? ( Hash ) || value . is_a? ( Array ) ) value = value . to_yaml end attrs [ self . class . arel_table [ name ] ] = value end end end attrs end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "or one digit followed by 0 - 2 zeroes ( 100 / 10 / 1 - bump major / minor / patch ) [CODESPLIT] def run usage \"[0.1.2 - version, 100/10/1 - bump major/minor/patch, .build - add build] Commit message goes here\" if @argv . empty? # First Arg may indicate version command if it matches pattern version_command = @argv [ 0 ] =~ COMMAND_PATTERN ? @argv . shift : nil # All the other args lumped into message, or default message if @argv . empty? commit_message = \"Commit #{Time.now.to_s[0..-6]}\" history_message = nil else commit_message = history_message = @argv . join ( ' ' ) end # Updating version only if version command set if version_command puts \"Updating version with #{version_command}\" if history_message system %Q{rake \"version[#{version_command},#{history_message}]\"} else system %Q{rake version[#{version_command}]} end end puts \"Adding all the changes\" system \"git add --all\" puts \"Committing everything with message: #{commit_message}\" system %Q[git commit -a -m \"#{commit_message}\" --author arvicco] current_branch = ` ` . strip puts \"Pushing to (default) remote for branch: #{current_branch}\" system \"git push\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _get_accessible_products [CODESPLIT] def _get ( cmd , ids , * _args ) # This is still in experimental and apparently the behavior was changed since 4.2. # We don't keep the backward-compatibility and just require the proper version here. requires_version ( cmd , 4.2 ) params = { } if ids . is_a? ( Hash ) raise ArgumentError , format ( 'Invalid parameter: %s' , ids . inspect ) unless ids . include? ( 'ids' ) || ids . include? ( 'names' ) params [ :ids ] = ids [ 'ids' ] || ids [ 'names' ] elsif ids . is_a? ( Array ) r = ids . map { | x | x . is_a? ( Integer ) ? x : nil } . compact if r . length != ids . length params [ :names ] = ids else params [ :ids ] = ids end else if ids . is_a? ( Integer ) params [ :ids ] = [ ids ] else params [ :names ] = [ ids ] end end @iface . call ( cmd , params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rdoc [CODESPLIT] def check_version ( version_ ) v = version f = false if v . is_a? ( Hash ) && v . include? ( 'version' ) && Gem :: Version . new ( v [ 'version' ] ) >= Gem :: Version . new ( version_ . to_s ) f = true end [ f , v [ 'version' ] ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def check_version rdoc [CODESPLIT] def requires_version ( cmd , version_ ) v = check_version ( version_ ) raise NoMethodError , format ( '%s is not supported in Bugzilla %s' , cmd , v [ 1 ] ) unless v [ 0 ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "default 10 minutes [CODESPLIT] def run begin Clacks . logger . info \"Clacks v#{Clacks::VERSION} started\" if Clacks . config [ :pop3 ] run_pop3 elsif Clacks . config [ :imap ] run_imap else raise \"Either a POP3 or an IMAP server must be configured\" end rescue Exception => e fatal ( e ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Follows mostly the defaults from the Mail gem [CODESPLIT] def imap_validate_options ( options ) options ||= { } options [ :mailbox ] ||= 'INBOX' options [ :count ] ||= 5 options [ :order ] ||= :asc options [ :what ] ||= :first options [ :keys ] ||= 'ALL' options [ :delete_after_find ] ||= false options [ :mailbox ] = Net :: IMAP . encode_utf7 ( options [ :mailbox ] ) if options [ :archivebox ] options [ :archivebox ] = Net :: IMAP . encode_utf7 ( options [ :archivebox ] ) end options end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "http : // tools . ietf . org / rfc / rfc2177 . txt [CODESPLIT] def imap_watchdog Thread . new do loop do begin Clacks . logger . debug ( 'watchdog sleeps' ) sleep ( WATCHDOG_SLEEP ) Clacks . logger . debug ( 'watchdog woke up' ) @imap . idle_done Clacks . logger . debug ( 'watchdog signalled idle process' ) rescue StandardError => e Clacks . logger . debug { \"watchdog received error: #{e.message} (#{e.class})\\n#{(e.backtrace || []).join(\"\\n\")}\" } # noop rescue Exception => e fatal ( e ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Keep processing emails until nothing is found anymore or until a QUIT signal is received to stop the process . [CODESPLIT] def imap_find ( imap ) options = Clacks . config [ :find_options ] delete_after_find = options [ :delete_after_find ] begin break if stopping? uids = imap . uid_search ( options [ :keys ] || 'ALL' ) uids . reverse! if options [ :what ] . to_sym == :last uids = uids . first ( options [ :count ] ) if options [ :count ] . is_a? ( Integer ) uids . reverse! if ( options [ :what ] . to_sym == :last && options [ :order ] . to_sym == :asc ) || ( options [ :what ] . to_sym != :last && options [ :order ] . to_sym == :desc ) processed = 0 expunge = false uids . each do | uid | break if stopping? source = imap . uid_fetch ( uid , [ 'RFC822' ] ) . first . attr [ 'RFC822' ] mail = nil begin mail = Mail . new ( source ) mail . mark_for_delete = true if delete_after_find Clacks . config [ :on_mail ] . call ( mail ) rescue StandardError => e Clacks . logger . error ( e . message ) Clacks . logger . error ( e . backtrace ) end begin imap . uid_copy ( uid , options [ :archivebox ] ) if options [ :archivebox ] if delete_after_find && ( mail . nil? || mail . is_marked_for_delete? ) expunge = true imap . uid_store ( uid , \"+FLAGS\" , [ Net :: IMAP :: DELETED ] ) end rescue StandardError => e Clacks . logger . error ( e . message ) end processed += 1 end imap . expunge if expunge end while uids . any? && processed == uids . length end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "options include : file and : base_url [CODESPLIT] def get_ead if @eadid . nil? and @url . nil? and @file . nil? and @baseurl raise 'Cannot get EAD based on params.' end if @file and @file . is_a? File @file . rewind if @file . eof? @ead = @file . read elsif @url @ead = open ( @url ) . read elsif @baseurl @ead = open ( File . join ( @baseurl , @eadid + '.xml' ) ) . read end @doc = Nokogiri :: XML ( @ead ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "delete the batch job and update status may raise PBS :: Error as it is unhandled here! [CODESPLIT] def stop ( update : true ) return unless status . active? job . delete update ( status : OSC :: Machete :: Status . failed ) if update end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Setter that accepts an OSC :: Machete :: Job instance [CODESPLIT] def job = ( new_job ) if self . has_attribute? ( :job_cache ) self . script = new_job . script_path . to_s self . pbsid = new_job . pbsid self . host = new_job . host if new_job . respond_to? ( :host ) else self . script_name = new_job . script_name self . job_path = new_job . path . to_s self . pbsid = new_job . pbsid end begin self . status = new_job . status rescue PBS :: Error => e # a safe default self . status = OSC :: Machete :: Status . queued # log the error Rails . logger . error ( \"After submitting the job with pbsid: #{pbsid},\" \" checking the status raised a PBS::Error: #{e.message}\" ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A hook that can be overidden with custom code also looks for default validation methods for existing WARNING : THIS USES ActiveSupport :: Inflector methods underscore and parameterize [CODESPLIT] def results_valid? valid = true if self . respond_to? ( :script_name ) && ! script_name . nil? if self . respond_to? ( results_validation_method_name ) valid = self . send ( results_validation_method_name ) end end valid end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "FIXME : should have a unit test for this! job . update_status! will update and save object if submitted? and ! completed? and status changed from previous state force will cause status to update regardless of completion status redoing the validations . This way if you are fixing validation methods you can use the Rails console to update the status of a Workflow by doing this : [CODESPLIT] def update_status! ( force : false ) # this will make it easier to differentiate from current_status cached_status = status # by default only update if its an active job if ( cached_status . not_submitted? && pbsid ) || cached_status . active? || force # get the current status from the system current_status = job . status # if job is done, lets re-validate if current_status . completed? current_status = results_valid? ? OSC :: Machete :: Status . passed : OSC :: Machete :: Status . failed end if ( current_status != cached_status ) || force self . status = current_status self . save end end rescue PBS :: Error => e # we log the error but we just don't update the status Rails . logger . error ( \"During update_status! call on job with pbsid #{pbsid} and id #{id}\" \" a PBS::Error was thrown: #{e.message}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Outputs usage notes ( and optional extended explanation ) then exits with code 1 [CODESPLIT] def usage ( examples , explanation = nil ) puts \"Script #{@name} #{version} - Usage:\" ( examples . respond_to? ( :split ) ? examples . split ( \"\\n\" ) : examples ) . map { | line | puts \"    #{@name} #{line}\" } puts explanation if explanation exit 1 end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TODO support a block ( solo dentro l blocco fai il nocolor ) [CODESPLIT] def set_color ( bool ) b = bool ? true : false deb \"Setting color mode to: #{yellow bool} --> #{white b.to_s}\" b = false if bool . to_s . match ( / / ) deb \"Setting color mode to: #{yellow bool} --> #{white b.to_s}\" $colors_active = bool end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "carattere per carattere ... [CODESPLIT] def rainbow ( str ) i = 0 ret = '' str = str . to_s while ( i < str . length ) ch = str [ i ] palette = $color_db [ 0 ] [ i % $color_db [ 0 ] . length ] ret << ( colora ( palette , str [ i , 1 ] ) ) i += 1 end ret end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "italia : green white red ireland : green white orange france : green white orange UK : blue white red white blue google : [CODESPLIT] def _flag_nations %w{ cc it de ie fr es en goo br pt } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "for simmetry padding m = length / 3 6 : 2 2 2 m m m REST 0 5 : 2 1 2 m + 1 m m + 1 2 4 : 1 2 1 m m + 1 m 1 [CODESPLIT] def flag3 ( str , left_color = 'brown' , middle_color = 'pink' , right_color = 'red' ) m = str . length / 3 remainder = str . length % 3 central_length = remainder == 1 ? m + 1 : m lateral_length = remainder == 2 ? m + 1 : m colora ( left_color , str [ 0 .. lateral_length - 1 ] ) + colora ( middle_color , str [ lateral_length .. lateral_length + central_length - 1 ] ) + colora ( right_color , str [ lateral_length + central_length .. str . length ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieves the next largest prime for the largest number in batch [CODESPLIT] def large_enough_prime ( input ) standard_primes . each do | prime | return prime if prime > input end fail CannotFindLargeEnoughPrime , \"Input too large\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Combines array into a string with given separator [CODESPLIT] def enhance_content ( value , separator = ', ' ) value . is_a? ( Array ) ? value . join ( separator ) : value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The null - byte character is prepended to be the first character in the charset to avoid loosing the first character of the charset when it is also the first character in a string to convert . [CODESPLIT] def i_to_s ( input ) if ! input . is_a? ( Integer ) || input < 0 fail NotPositiveInteger , \"input must be a non-negative integer\" end output = \"\" while input > 0 input , codepoint = input . divmod ( charset . length ) output . prepend ( codepoint_to_char ( codepoint ) ) end output end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculate an integer from a string . [CODESPLIT] def s_to_i ( string ) string . chars . reduce ( 0 ) do | output , char | output * charset . length + char_to_codepoint ( char ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert an integer into its string representation according to the charset . ( only one character ) [CODESPLIT] def codepoint_to_char ( codepoint ) if charset . at ( codepoint ) . nil? fail NotInCharset , \"Codepoint #{codepoint} does not exist in charset\" end charset . at ( codepoint ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convert a single character into its integer representation according to the charset . [CODESPLIT] def char_to_codepoint ( c ) codepoint = charset . index c if codepoint . nil? fail NotInCharset , \"Char \\\"#{c}\\\" not part of the supported charset\" end codepoint end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Check if the provided string can be represented by the charset . [CODESPLIT] def subset? ( string ) ( Set . new ( string . chars ) - Set . new ( charset ) ) . empty? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new instance of a Polynomial with n coefficients when having the polynomial in standard polynomial form . [CODESPLIT] def points ( num_points , prime ) intercept = @coefficients [ 0 ] # the first coefficient is the intercept ( 1 .. num_points ) . map do | x | y = intercept ( 1 ... @coefficients . length ) . each do | i | y = ( y + @coefficients [ i ] * x ** i ) % prime end Point . new ( x , y ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def read_config [CODESPLIT] def save_config ( opts , conf ) fname = opts [ :config ] . nil? ? @defaultyamlfile : opts [ :config ] if File . exist? ( fname ) st = File . lstat ( fname ) if st . mode & 0o600 != 0o600 raise format ( 'The permissions of %s has to be 0600' , fname ) end end File . open ( fname , 'w' ) { | f | f . chmod ( 0o600 ) ; f . write ( conf . to_yaml ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a new EadValidator when given the path to a directory as a String [CODESPLIT] def validate! files = Dir . glob ( File . join ( @directory , '*.xml' ) ) . sort threads = [ ] files . map do | path | threads << Thread . new ( path ) do | path_t | eadid = File . basename ( path_t , '.xml' ) begin ead = Mead :: Ead . new ( { :file => File . open ( path_t ) , :eadid => eadid } ) rescue => e record_invalid ( eadid , ead , e ) next end if ead . valid? @valid << eadid else record_invalid ( eadid , ead ) end end end threads . each { | thread | thread . join } metadata end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Broadcast notifications when a new record is created [CODESPLIT] def notify_create self . ChannelPublications . each do | publication , options | if options [ :actions ] . include? :create # Checks if records is within scope before broadcasting records = self . class . scoped_collection ( options [ :scope ] ) if options [ :scope ] == :all or record_within_scope ( records ) ActionCable . server . broadcast publication , msg : 'create' , id : self . id , data : self end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Broadcast notifications when a record is updated . Only changed fields will be sent if they are within configured scope [CODESPLIT] def notify_update # Get model changes if self . respond_to? ( :saved_changes ) # For Rails >= 5.1 changes = self . saved_changes . transform_values ( :second ) else # For Rails < 5.1 changes = self . changes . transform_values ( :second ) end # Checks if there are changes in the model if ! changes . empty? self . ChannelPublications . each do | publication , options | if options [ :actions ] . include? :update # Checks if previous record was within scope record = record_within_scope ( options [ :records ] ) was_in_scope = record . present? options [ :records ] . delete ( record ) if was_in_scope # Checks if current record is within scope if options [ :track_scope_changes ] == true is_in_scope = false if options [ :scope ] == :all record = self is_in_scope = true else record = record_within_scope ( self . class . scoped_collection ( options [ :scope ] ) ) if record . present? is_in_scope = true end end else is_in_scope = was_in_scope end # Broadcasts notifications about model changes if is_in_scope if was_in_scope # Get model changes and applies them to the scoped collection record changes . select! { | k , v | record . respond_to? ( k ) } if ! changes . empty? ActionCable . server . broadcast publication , msg : 'update' , id : self . id , data : changes end else ActionCable . server . broadcast publication , msg : 'create' , id : record . id , data : record end elsif was_in_scope # checks if needs to delete the record if its no longer in scope ActionCable . server . broadcast publication , msg : 'destroy' , id : self . id end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Broadcast notifications when a record is destroyed . [CODESPLIT] def notify_destroy self . ChannelPublications . each do | publication , options | if options [ :scope ] == :all or options [ :actions ] . include? :destroy # Checks if record is within scope before broadcasting if options [ :scope ] == :all or record_within_scope ( self . class . scoped_collection ( options [ :scope ] ) ) . present? ActionCable . server . broadcast publication , msg : 'destroy' , id : self . id end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the Logger - like object . The default Logger will log its output to Rails . logger if you re running within a rails environment otherwise it will output to the path specified by + stdout_path + . [CODESPLIT] def logger ( obj ) %w( debug info warn error fatal level ) . each do | m | next if obj . respond_to? ( m ) raise ArgumentError , \"logger #{obj} does not respond to method #{m}\" end map [ :logger ] = obj end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "From rails / activemodel / lib / active_model / validations / clusivity . rb : In Ruby 1 . 9 <tt > Range#include?< / tt > on non - number - or - time - ish ranges checks all possible values in the range for equality which is slower but more accurate . <tt > Range#cover?< / tt > uses the previous logic of comparing a value with the range endpoints which is fast but is only accurate on Numeric Time or DateTime ranges . [CODESPLIT] def inclusion_method enumerable if enumerable . is_a? Range case enumerable . first when Numeric , Time , DateTime :cover? else :include? end else :include? end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Base constructor Returns a Mechanize :: Page instance which is the being searched on . If the page was once fetched it s reuse . To reload call with an argument evaluating to true . [CODESPLIT] def page ( reload = false ) return nil if url . nil? if reload @page = Mechanize . new . get ( url ) else @page ||= Mechanize . new . get ( url ) end @page end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Method which calls all rate fetching methods from the sub class and returns a Hash with appropriate values . [CODESPLIT] def fetch_rates if self . class . superclass . eql? ( Object ) raise Exception . new ( \"This method should be invoked from CurrencySpy::Scraper sub class\" ) else check_currency_code_validity rate_results = { } RATE_DATA . each do | rate | symbol = rate . to_sym if self . class . instance_methods . include? ( symbol ) value = self . send ( symbol ) rate_results [ symbol ] = value unless value . nil? end end rate_results end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parameters : One of the following must be specified : queue_name = > String : Name of the Queue to publish to : topic_name = > String : Name of the Topic to publish to Optional : : time_to_live = > expiration time in ms for the message ( JMS ) : persistent = > true or false ( defaults to false ) ( JMS ) : marshal = > Symbol : One of : ruby : string : json : bson : yaml or any registered types ( See Qwirk :: MarshalStrategy ) defaults to : ruby : response = > if true or a hash of response options a temporary reply queue will be setup for handling responses : time_to_live = > expiration time in ms for the response message ( s ) ( JMS )) : persistent = > true or false for the response message ( s ) set to false if you don t want timed out messages ending up in the DLQ ( defaults to true unless time_to_live is set ) Publish the given object to the address . [CODESPLIT] def publish ( object , props = { } ) start = Time . now marshaled_object = @marshaler . marshal ( object ) adapter_info = @impl . publish ( marshaled_object , @marshaler , nil , props ) return PublishHandle . new ( self , adapter_info , start ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parse the source string for a target string or regex or return nil . [CODESPLIT] def parse ( target ) #Handle the width option if specified.\r if ( width = fmt . width ) > 0 head , tail = src [ 0 ... width ] , src [ width .. - 1 ] || \"\" else head , tail = src , \"\" end #Do the parse on the input string or regex.\r @prematch , @match , @postmatch = head . partition ( target ) #Analyze the results.\r if found? @src = @postmatch + tail @match else nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Grab some text [CODESPLIT] def grab width = fmt . width if width > 0 result , @src = src [ 0 ... width ] , src [ width .. - 1 ] || \"\" elsif width == 0 result , @src = src [ 0 ... 1 ] , src [ 1 .. - 1 ] || \"\" elsif width == - 1 result , @src = src , \"\" else result , @src = src [ 0 .. width ] , src [ ( width + 1 ) .. - 1 ] || \"\" end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def get_bugs rdoc [CODESPLIT] def get_comments ( bugs ) params = { } # TODO # this construction should be refactored to a method params [ 'ids' ] = case bugs when Array bugs when Integer || String [ bugs ] else raise ArgumentError , format ( 'Unknown type of arguments: %s' , bugs . class ) end result = comments ( params ) # not supporting comment_ids. so drop \"comments\". ret = result [ 'bugs' ] # creation_time was added in Bugzilla 4.4. copy the 'time' value to creation_time if not available for compatibility. unless check_version ( 4.4 ) [ 0 ] ret . each do | _id , o | o [ 'comments' ] . each do | c | c [ 'creation_time' ] = c [ 'time' ] unless c . include? ( 'creation_time' ) end end end ret end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _fields [CODESPLIT] def _legal_values ( cmd , * args ) raise ArgumentError , 'Invalid parameters' unless args [ 0 ] . is_a? ( Hash ) @iface . call ( cmd , args [ 0 ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _comments [CODESPLIT] def _get ( cmd , * args ) params = { } a = args [ 0 ] case a when Hash params = a when Array params [ 'ids' ] = a when Integer || String params [ 'ids' ] = [ a ] else raise ArgumentError , 'Invalid parameters' end params [ 'permissive' ] = true if check_version ( 3.4 ) [ 0 ] @iface . call ( cmd , params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _get [CODESPLIT] def _history ( cmd , * args ) requires_version ( cmd , 3.4 ) params = { } a = args [ 0 ] case a when Hash params = a when Array params [ 'ids' ] = a when Integer || String params [ 'ids' ] = [ a ] else raise ArgumentError , 'Invalid parameters' end @iface . call ( cmd , params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _search [CODESPLIT] def _create ( cmd , * args ) raise ArgumentError , 'Invalid parameters' unless args [ 0 ] . is_a? ( Hash ) required_fields = %i[ product component summary version ] defaulted_fields = %i[ description op_sys platform priority severity ] res = check_version ( '3.0.4' ) required_fields . push ( defaulted_fields ) unless res [ 0 ] required_fields . each do | f | raise ArgumentError , format ( \"Required fields isn't given: %s\" , f ) unless args [ 0 ] . include? ( f ) end res = check_version ( 4.0 ) if res [ 0 ] if args [ 0 ] . include? ( 'commentprivacy' ) args [ 0 ] [ 'comment_is_private' ] = args [ 0 ] [ 'commentprivacy' ] args [ 0 ] . delete ( 'commentprivacy' ) end else raise ArgumentError , \"groups field isn't available in this bugzilla\" if args [ 0 ] . include? ( 'groups' ) raise ArgumentError , \"comment_is_private field isn't available in this bugzilla\" if args [ 0 ] . include? ( 'comment_is_private' ) end @iface . call ( cmd , args [ 0 ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create message [CODESPLIT] def save! self . class . create! ( contact . is_a? HashBlue :: Contact ? contact . phone_number : contact , content ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Define a parser for the current class . <br > Parameters * method - A symbol used to name the parsing method created by this method . * library - A hash of parsing rules the define the parsing capabilities supported by this parser . <br > Meta - effects * Creates a class method ( named after the symbol in method ) that parses in a string and creates an instance of the class . The created method takes two parameters : <br > Meta - method Parameters * src - A string of formatted data to be parsed . * spec_str - A format specification string with %x etc qualifiers . <br > Meta - method Returns * An instance of the host class . <br > Returns * The format engine used by this method . [CODESPLIT] def attr_parser ( method , library ) engine = Engine . new ( library ) #Create a class method to do the parsing.\r define_singleton_method ( method ) do | src , spec_str | engine . do_parse ( src , self , spec_str ) end engine end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note Get GoogleDirectory User Info [CODESPLIT] def user_get ( attributes : ) response = service . get_user ( attributes [ :primary_email ] ) { response : response , attributes : attributes [ :primary_email ] , command : :user_get } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note Test if user exists in Google Directory [CODESPLIT] def user_exists? ( attributes : ) begin response = service . get_user ( attributes [ :primary_email ] ) return { response : true , attributes : attributes [ :primary_email ] , command : :user_exists? } rescue Google :: Apis :: ClientError => error if error . message . include? 'notFound' return { response : false , attributes : attributes [ :primary_email ] , command : :user_exists? } else raise error end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note creates a new Google Directory User [CODESPLIT] def user_create ( attributes : ) # http://blog.liveedu.tv/ruby-generate-random-string/ password = SecureRandom . base64 defaults = { suspended : true , password : password , change_password_at_next_login : true } user_attr = defaults . merge ( attributes ) # create a google user object user_object = Google :: Apis :: AdminDirectoryV1 :: User . new user_attr # create user in directory services response = service . insert_user ( user_object ) { response : response , attributes : attributes [ :primary_email ] , command : :user_create } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note updates an exising Google Directory User [CODESPLIT] def user_update ( attributes : ) # create a user object for google to update response = update_user ( attributes ) { response : response , attributes : attributes [ :primary_email ] , command : :user_update } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note updates an exising Google Directory User password - convience method instead of using : user_update [CODESPLIT] def user_change_password ( attributes : ) password = SecureRandom . base64 defaults = { password : password , change_password_at_next_login : true } user_attr = defaults . merge ( attributes ) response = update_user ( user_attr ) { response : response , attributes : attributes [ :primary_email ] , command : :user_change_password } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note activates an exising Google Directory User password - convience method instead of using : user_update [CODESPLIT] def user_reactivate ( attributes : ) defaults = { :suspended => false } user_attr = defaults . merge ( attributes ) response = update_user ( user_attr ) { response : response , attributes : attributes [ :primary_email ] , command : :user_reactivate } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note suspends an exising Google Directory User password - convience method instead of using : user_update [CODESPLIT] def user_suspend ( attributes : ) defaults = { :suspended => true } user_attr = defaults . merge ( attributes ) response = update_user ( user_attr ) { response : response , attributes : attributes [ :primary_email ] , command : :user_suspend } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note deletes an exising Google Directory User [CODESPLIT] def user_delete ( attributes : ) response = service . delete_user ( attributes [ :primary_email ] ) { response : response , attributes : attributes [ :primary_email ] , command : :user_delete } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Constructs a manager . Accepts a hash of config options name - name which this bean will be added env - environment being executed under . For a rails project this will be the value of Rails . env worker_file - the worker file is a hash with the environment or hostname as the primary key and a subhash with the worker names as the keys and the config options for the value . In this file the env will be searched first and if that doesn t exist the hostname will then be searched . Workers can be defined for development without having to specify the hostname . For production a set of workers could be defined under production or specific workers for each host name . persist_file - WorkerConfig attributes that are modified externally ( via Rumx interface ) will be stored in this file . Without this option external config changes that are made will be lost when the Manager is restarted . Create a timer_thread to make periodic calls to the worker_configs in order to do such things as expand / contract workers etc . [CODESPLIT] def start_timer_thread @timer_thread = Thread . new do begin while ! @stopped @worker_configs . each do | worker_config | worker_config . periodic_call ( @poll_time ) end sleep @poll_time end rescue Exception => e Qwirk . logger . error \"Timer thread failed with exception: #{e.message}\\n\\t#{e.backtrace.join(\"\\n\\t\")}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Store off any options that are no longer set to default [CODESPLIT] def save_persist_state return unless @persist_file new_persist_options = { } BaseWorker . worker_classes . each do | worker_class | worker_class . each_config ( @adapter_factory . worker_config_class ) do | config_name , ignored_extended_worker_config_class , default_options | static_options = default_options . merge ( @worker_options [ config_name ] || { } ) worker_config = self [ config_name ] hash = { } # Only store off the config values that are specifically different from default values or values set in the workers.yml file # Then updates to these values will be allowed w/o being hardcoded to an old default value. worker_config . bean_get_attributes do | attribute_info | if attribute_info . attribute [ :config_item ] && attribute_info . ancestry . size == 1 param_name = attribute_info . ancestry [ 0 ] . to_sym value = attribute_info . value hash [ param_name ] = value if static_options [ param_name ] != value end end new_persist_options [ config_name ] = hash unless hash . empty? end end if new_persist_options != @persist_options @persist_options = new_persist_options File . open ( @persist_file , 'w' ) do | out | YAML . dump ( @persist_options , out ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "after calling this action I expect the titles and revisions to be filled [CODESPLIT] def read_pages # get all projects results_projects = database . query ( \"SELECT id, identifier, name FROM projects;\" ) results_projects . each do | row_project | #collect all namespaces namespaces << OpenStruct . new ( identifier : row_project [ \"identifier\" ] , name : row_project [ \"name\" ] ) end # get all wikis results_wikis = database . query ( \"SELECT id, project_id FROM wikis;\" ) # get all lemmas results_pages = database . query ( \"SELECT id, title, wiki_id FROM wiki_pages;\" ) results_pages . each do | row_page | results_contents = database . query ( \"SELECT * FROM wiki_content_versions WHERE page_id='#{row_page[\"id\"]}' ORDER BY updated_on;\" ) # get wiki for page wiki_row = nil project_row = nil results_wikis . each do | wiki | wiki_row = wiki if wiki [ \"id\" ] == row_page [ \"wiki_id\" ] end if wiki_row # get project from wiki-id results_projects . each do | project | project_row = project if project [ \"id\" ] == wiki_row [ \"project_id\" ] end end project_identifier = project_row ? project_row [ \"identifier\" ] + '/' : \"\" title = project_identifier + row_page [ \"title\" ] titles << title @latest_revisions = { } results_contents . each do | row_content | author = authors [ row_content [ \"author_id\" ] ] ? @authors [ row_content [ \"author_id\" ] ] : nil page = Page . new ( { :id => row_content [ \"id\" ] , :title => title , :body => row_content [ \"data\" ] , :markup => :textile , :latest => false , :time => row_content [ \"updated_on\" ] , :message => row_content [ \"comments\" ] , :author => author , :author_name => author . name } ) revisions << page @latest_revisions [ title ] = page end end titles . uniq! @latest_revisions . each { | rev | rev [ 1 ] . set_latest } revisions . sort! { | a , b | a . time <=> b . time } # TODO find latest revision for each limit revisions end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "NOTE : this method will be removed on next release [CODESPLIT] def upgrade_file_key ( key , save = true ) cname = self . collection . name files = self . database [ \"#{cname}.files\" ] chunks = self . database [ \"#{cname}.chunks\" ] fname = self [ \"_#{key}\" ] rescue nil return if fname . blank? begin n = Mongo :: GridIO . new ( files , chunks , fname , \"r\" , :query => { :filename => fname } ) v = n . read if ! v . empty? data = StringIO . new ( v ) self . put_file ( key , data ) self [ \"_#{key}\" ] = nil self . save ( :validate => false ) if save end rescue => e puts \"ERROR: #{e}\" puts e . backtrace . join ( \"\\t\\n\" ) return end files . remove ( :_id => fname ) chunks . remove ( :_id => fname ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Waits the given timeout for a response message on the queue . [CODESPLIT] def read_response ( timeout , & block ) raise \"Invalid call to read_response for #{@producer}, not setup for responding\" unless @producer . response_options # Creates a block for reading the responses for a given message_id (adapter_info).  The block will be passed an object # that responds to timeout_read(timeout) with a [original_message_id, response_message, worker_name] tri or nil if no message is read. # This is used in the RPC mechanism where a publish might wait for 1 or more workers to respond. @producer . impl . with_response ( @adapter_info ) do | consumer | if block_given? return read_multiple_response ( consumer , timeout , block ) else tri = read_single_response ( consumer , timeout ) if tri response = tri [ 1 ] raise response if response . kind_of? ( Qwirk :: RemoteException ) return response else @timeout = ! tri return nil end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "if a line doesn t match any of the patterns then [CODESPLIT] def add_filter ( id , pattern , & block ) filter = LineFilter . new ( id , pattern , block ) @filters << filter end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Selected option ( s ) of this Select . [CODESPLIT] def field_value opts = selected_options opts . count == 1 ? opts . first . text : opts . map ( :text ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Define a formatter for instances of the current class . <br > Parameters * method - A symbol used to name the formatting method created by this method . * library - A hash of formatting rules that define the formatting capabilities supported by this formatter . <br > Meta - effects * Creates a method ( named after the symbol in method ) that formats the instance of the class . The created method takes one parameter : <br > Meta - method Parameters * spec_str - A format specification string with %x etc qualifiers . <br > Meta - method Returns * A formatted string <br > Returns * The format engine used by this method . [CODESPLIT] def attr_formatter ( method , library ) engine = Engine . new ( library ) #Create an instance method to do the formatting.\r define_method ( method ) do | spec_str | engine . do_format ( self , spec_str ) end engine end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Print selected nodes to stdout [CODESPLIT] def write ( template = nil ) if not template . nil? then template = template . to_mixml_template end each_node do | node | if template . nil? then node . write_xml_to ( $stdout ) puts else puts template . evaluate ( node ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replace selected nodes with a template [CODESPLIT] def replace ( template ) template = template . to_mixml_template each_node do | node | value = template . evaluate ( node ) node . replace ( value ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rename selected nodes with a template [CODESPLIT] def rename ( template ) template = template . to_mixml_template each_node do | node | value = template . evaluate ( node ) node . name = value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Commit the given page into the gollum - wiki - repository . Make sure the target markup is correct before calling this method . [CODESPLIT] def commit_revision ( page , markup ) gollum_page = gollum . page ( page . title ) if gollum_page gollum . update_page ( gollum_page , gollum_page . name , gollum_page . format , page . body , build_commit ( page ) ) else gollum . write_page ( page . title , markup , page . body , build_commit ( page ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Commit all revisions of the given history into this gollum - wiki - repository . [CODESPLIT] def commit_history ( revisions , options = { } , & block ) options [ :markup ] = :markdown if ! options [ :markup ] # target markup revisions . each_with_index do | page , index | # call debug output from outside block . call ( page , index ) if block_given? commit_revision ( page , options [ :markup ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Scan the format string extracting literals and variables . [CODESPLIT] def scan_spec ( fmt_string ) until fmt_string . empty? if ( match_data = PARSE_REGEX . match ( fmt_string ) ) mid = match_data . to_s pre = match_data . pre_match @specs << FormatLiteral . new ( pre ) unless pre . empty? @specs << case when match_data [ :var ] then FormatVariable . new ( mid ) when match_data [ :set ] then FormatSet . new ( mid ) when match_data [ :rgx ] then FormatRgx . new ( mid ) when match_data [ :per ] then FormatLiteral . new ( \"\\%\" ) else fail \"Impossible case in scan_spec.\" end fmt_string = match_data . post_match else @specs << FormatLiteral . new ( fmt_string ) fmt_string = \"\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@note Run a command against Google Directory [CODESPLIT] def run ( command : , attributes : { } ) response = { } begin response = send ( command , attributes : attributes ) response [ :status ] = 'success' rescue Google :: Apis :: ClientError => error response = { status : 'error' , response : error , attributes : attributes , command : command , } end response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "take an input stream and convert all wikka syntax to markdown syntax taken from trac_wiki_to_textile at [CODESPLIT] def to_textile str body = body . dup body . gsub! ( / \\r / , '' ) body . gsub! ( / \\{ \\{ \\{ \\n \\} \\} \\} / , '@\\1@' ) body . gsub! ( / \\{ \\{ \\{ \\n \\n \\} \\} \\} /m , '<pre><code class=\"\\1\">\\2</code></pre>' ) body . gsub! ( / \\{ \\{ \\{ \\} \\} \\} /m , '<pre>\\1</pre>' ) # macro body . gsub! ( / \\[ \\[ \\] \\] / , '' ) body . gsub! ( / \\[ \\[ \\] \\] / , '{{toc}}' ) body . gsub! ( / \\[ \\[ \\( \\) \\] \\] / , '!\\1!' ) # header body . gsub! ( / \\s \\s / , \"h5. #{'\\1'} \\n\\n\" ) body . gsub! ( / \\s \\s / , \"h4. #{'\\1'} \\n\\n\" ) body . gsub! ( / \\s \\s / , \"h3. #{'\\1'} \\n\\n\" ) body . gsub! ( / \\s \\s / , \"h2. #{'\\1'} \\n\\n\" ) body . gsub! ( / \\s \\s \\s \\n / , \"h1. #{'\\1'} \\n\\n\" ) # table body . gsub! ( / \\| \\| / , \"|\" ) # link body . gsub! ( / \\[ \\s \\[ \\] \\s \\[ \\] \\] / , ' \"\\2\":\\1' ) body . gsub! ( / \\[ \\s \\s \\] / , ' [[\\1 | \\2]] ' ) body . gsub! ( / \\/ \\! / , ' \\1[[\\2]] ' ) body . gsub! ( / \\! / , '\\1' ) # text decoration body . gsub! ( / / , '*\\1*' ) body . gsub! ( / / , '_\\1_' ) body . gsub! ( / / , '@\\1@' ) # itemize body . gsub! ( / \\s \\s \\s \\* / , '***' ) body . gsub! ( / \\s \\s \\* / , '**' ) body . gsub! ( / \\s \\* / , '*' ) body . gsub! ( / \\s \\s \\s \\d \\. / , '###' ) body . gsub! ( / \\s \\s \\d \\. / , '##' ) body . gsub! ( / \\s \\d \\. / , '#' ) body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TODO this is so far only copy of textile conversion not tested! [CODESPLIT] def to_markdown str body = body . dup body . gsub! ( / \\r / , '' ) body . gsub! ( / \\{ \\{ \\{ \\n \\} \\} \\} / , '@\\1@' ) body . gsub! ( / \\{ \\{ \\{ \\n \\n \\} \\} \\} /m , '<pre><code class=\"\\1\">\\2</code></pre>' ) body . gsub! ( / \\{ \\{ \\{ \\} \\} \\} /m , '<pre>\\1</pre>' ) # macro body . gsub! ( / \\[ \\[ \\] \\] / , '' ) body . gsub! ( / \\[ \\[ \\] \\] / , '{{toc}}' ) body . gsub! ( / \\[ \\[ \\( \\) \\] \\] / , '!\\1!' ) # header body . gsub! ( / \\s \\s / , \"== #{'\\1'} ==\\n\\n\" ) body . gsub! ( / \\s \\s / , \"=== #{'\\1'} ===\\n\\n\" ) body . gsub! ( / \\s \\s / , \"==== #{'\\1'} ====\\n\\n\" ) body . gsub! ( / \\s \\s / , \"===== #{'\\1'} =====\\n\\n\" ) body . gsub! ( / \\s \\s \\s \\n / , \"====== #{'\\1'} ======\\n\\n\" ) # table body . gsub! ( / \\| \\| / , \"|\" ) # link body . gsub! ( / \\[ \\s \\[ \\] \\s \\[ \\] \\] / , ' \"\\2\":\\1' ) body . gsub! ( / \\[ \\s \\s \\] / , ' [[\\1 | \\2]] ' ) body . gsub! ( / \\/ \\! / , ' \\1[[\\2]] ' ) body . gsub! ( / \\! / , '\\1' ) # text decoration body . gsub! ( / / , '*\\1*' ) body . gsub! ( / / , '_\\1_' ) body . gsub! ( / / , '@\\1@' ) # itemize body . gsub! ( / \\s \\s \\s \\* / , '***' ) body . gsub! ( / \\s \\s \\* / , '**' ) body . gsub! ( / \\s \\* / , '*' ) body . gsub! ( / \\s \\s \\s \\d \\. / , '###' ) body . gsub! ( / \\s \\s \\d \\. / , '##' ) body . gsub! ( / \\s \\d \\. / , '#' ) body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "supports : strings arrays and regexes : ) [CODESPLIT] def autoregex ( anything ) deb \"Autoregex() supercool! With a #{blue anything.class}\" case anything . class . to_s when 'String' if anything . match ( / \\/ \\/ / ) # '/asd/' is probably an error! The regex builder trails with '/' automatically fatal 23 , \"Attention, the regex is a string with trailing '/', are you really SURE this is what you want?!?\" end return Regexp . new ( anything ) when 'Regexp' return anything # already ok when 'Array' return Regexp . new ( anything . join ( '|' ) ) else msg = \"Unknown class for autoregexing: #{red anything.class}\" $stderr . puts ( msg ) raise ( msg ) end return nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "shouldnt work right now yet .. [CODESPLIT] def debug2 ( s , opts = { } ) out = opts . fetch ( :out , $stdout ) tag = opts . fetch ( :tag , '_DFLT_' ) really_write = opts . fetch ( :really_write , true ) # you can prevent ANY debug setting this to false write_always = opts . fetch ( :write_always , false ) raise \"ERROR: ':tags' must be an array in debug(), maybe you meant to use :tag?\" if ( opts [ :tags ] && opts [ :tags ] . class != Array ) final_str = \"#RDeb#{write_always ? '!' : ''}[#{opts[:tag] || '-'}] #{s}\" final_str = \"\\033[1;30m\" + final_str + \"\\033[0m\" if opts . fetch ( :coloured_debug , true ) # color by gray by default if ( debug_tags_enabled? ) # tags puts ( final_str ) if debug_tag_include? ( opts ) else # normal behaviour: if NOT tag puts ( final_str ) if ( ( really_write && $DEBUG ) || write_always ) && ! opts [ :tag ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes a command during the shell session . [CODESPLIT] def exec ( command , options = { } , & block ) raise ConnectionClosed . new ( 'Connection is closed.' ) unless @channel options = { on_non_zero_exit_code : :default } . merge ( options || { } ) options [ :on_non_zero_exit_code ] = @options [ :on_non_zero_exit_code ] if options [ :on_non_zero_exit_code ] == :default push_buffer # store the current buffer and start a fresh buffer # buffer while also passing data to the supplied block. if block_given? buffer_input ( block ) end # send the command and wait for the prompt to return. @channel . send_data command + \"\\n\" wait_for_prompt # return buffering to normal. if block_given? buffer_input end # get the output from the command, minus the trailing prompt. ret = command_output ( command ) # restore the original buffer and merge the output from the command. pop_merge_buffer if @options [ :retrieve_exit_code ] # get the exit code for the command. push_buffer retrieve_command = 'echo $?' @channel . send_data retrieve_command + \"\\n\" wait_for_prompt @last_exit_code = command_output ( retrieve_command ) . strip . to_i # restore the original buffer and discard the output from this command. pop_discard_buffer # if we are expected to raise an error, do so. if options [ :on_non_zero_exit_code ] == :raise_error raise NonZeroExitCode . new ( \"Exit code was #{@last_exit_code}.\" ) unless @last_exit_code == 0 end end ret end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Uses SFTP to upload a single file to the host . [CODESPLIT] def upload ( local_file , remote_file ) raise ConnectionClosed . new ( 'Connection is closed.' ) unless @ssh sftp . upload! ( local_file , remote_file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Uses SFTP to download a single file from the host . [CODESPLIT] def download ( remote_file , local_file ) raise ConnectionClosed . new ( 'Connection is closed.' ) unless @ssh sftp . download! ( remote_file , local_file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Uses SFTP to write data to a single file . [CODESPLIT] def write_file ( remote_file , data ) raise ConnectionClosed . new ( 'Connection is closed.' ) unless @ssh sftp . file . open ( remote_file , 'w' ) do | f | f . write data end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Measure the distance between this point and another . [CODESPLIT] def distance ( other ) unless other . is_a? Point raise ArgumentError . new 'other must be a Point.' end dlng = GpsUtils :: to_radians ( other . lng - @lng ) dlat = GpsUtils :: to_radians ( other . lat - @lat ) x = dlng * Math . cos ( dlat / 2 ) y = GpsUtils :: to_radians ( other . lat - @lat ) Math . sqrt ( x ** 2 + y ** 2 ) * GpsUtils :: R end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialize BoundingBox . [CODESPLIT] def cover? ( point ) p = [ point . lat - @nw . lat , point . lng - @se . lng ] p21x = p [ 0 ] * @p21 p41x = p [ 1 ] * @p41 0 < p21x and p21x < @p21ms and 0 <= p41x and p41x <= @p41ms end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "for will paginate support [CODESPLIT] def send ( method , * args , & block ) if respond_to? ( method ) super else subject . send ( method , args , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "= begin # This tries to implement the xcopy for my git programs # similar to xcopy Originally called tra va sa = end [CODESPLIT] def xcopy ( from , to , glob_files , opts = { } ) n_actions = 0 puts \"+ Travasing: #{yellow from} ==> #{green to}\" verbose = opts . fetch :verbose , true dryrun = opts . fetch :dryrun , true # i scared of copying files! unless File . exists? ( \"#{to}/.git\" ) fatal 11 , \"Sorry cant travase data to an unversioned dir. Please version it with git (or add a .git dir/file to trick me)\" exit 1 end unless File . exists? ( \"#{to}/.safe_xcopy\" ) fatal 12 , \"Sorry I refuse to xcopy data unless you explicitly ask me to. You have to do this before:\\n  #{yellow \"touch #{to}/.safe_xcopy\"} . \n       You are for sure a very smart person but there are a LOT of people out there who could destroy theyr file system! Thanks\" end # With this i can understand what has been deleted, with lots of magic from git on both ends.. :) deb \"+ First the differences:\" deb ` #{ from } #{ to } \\\\ ` puts \"Dryrun is: #{azure dryrun}\" puts \"+ Files: #{cyan glob_files}\" Dir . chdir ( from ) Dir . glob ( glob_files ) . each { | file | from_file = \"#{from}/#{file}\" to_file = \"#{to}/#{file}\" destdir = File . dirname ( to_file ) deb \"Copying: #{yellow from_file}..\" #  could need creating the dir.. if File . exists? ( destdir ) # just copy the file command = \"cp \\\"#{from_file}\\\" \\\"#{to_file}\\\"\" else # mkdir dest AND copy file pred \"Hey, Dir '#{destdir}' doesnt exist! Creating it..\" command = \"mkdir -p \\\"#{destdir}\\\" && cp \\\"#{from_file}\\\" \\\"#{to_file}\\\"\" end if dryrun puts \"[DRYRUN] Skipping #{gray command}\" else ret = ` #{ command } ` puts \"EXE: #{gray command}\" if verbose n_actions += 1 print ( \"[ret=$?]\" , ret , \"\\n\" ) if ( ret . length > 1 || $? != 0 ) # if output or not zero end } puts \"#{n_actions} commands executed.\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Called to output the result to the console . [CODESPLIT] def output ( elapsed ) case @result when MATCH_SUCCESS color = :green header = 'OK' when MATCH_FAILURE color = :red header = 'FAIL' when MATCH_WARNING color = :light_red header = 'WARN' end header = header . ljust ( 12 ) . colorize ( color ) str_elapsed = \"#{elapsed.round(2)}s\" name = @name . to_s [ 0 .. 17 ] puts \"#{header}   #{name.ljust(20)}   #{str_elapsed.ljust(9)} #{@message}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rdoc [CODESPLIT] def session ( user , password ) key , fname = authentication_method # TODO # make those variables available host = @iface . instance_variable_get ( :@xmlrpc ) . instance_variable_get ( :@host ) conf = load_authentication_token ( fname ) val = conf . fetch ( host , nil ) if ! val . nil? if key == :token @iface . token = val else @iface . cookie = val end yield elsif user . nil? || password . nil? yield return else login ( 'login' => user , 'password' => password , 'remember' => true ) yield end conf [ host ] = @iface . send ( key ) if %i[ token cookie ] . include? key save_authentication_token ( fname , conf ) key end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def session rdoc [CODESPLIT] def get_userinfo ( user ) p = { } ids = [ ] names = [ ] if user . is_a? ( Array ) user . each do | u | names << u if u . is_a? ( String ) id << u if u . is_a? ( Integer ) end elsif user . is_a? ( String ) names << user elsif user . is_a? ( Integer ) ids << user else raise ArgumentError , format ( 'Unknown type of arguments: %s' , user . class ) end result = get ( 'ids' => ids , 'names' => names ) result [ 'users' ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def _update [CODESPLIT] def _get ( cmd , * args ) raise ArgumentError , 'Invalid parameters' unless args [ 0 ] . is_a? ( Hash ) requires_version ( cmd , 3.4 ) res = @iface . call ( cmd , args [ 0 ] ) # FIXME end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Instance Methods -------------------------------------------------------- [CODESPLIT] def banker_convert_currency ( value , conversion ) case conversion . to_sym when :to_cents return ( value . to_s . gsub ( / / , '' ) . to_d * 100 ) . to_i when :to_dollars return \"%0.2f\" % ( value . to_f / 100 ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "define a DSL for options any string is processed as an option and it ends up in the [CODESPLIT] def options & block options = Options . new options . instance_eval ( block ) @options = options . to_hash end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "define a DSL for column specification - name is the name of the column - block contains two declarations process and check which are used respectively to make a cell into the desired data and to check whether the desired data is ok [CODESPLIT] def column name , & block column = Column . new column . instance_eval ( block ) @colspec << column . to_hash . merge ( { name : name } ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "bulk declare columns we intend to read [CODESPLIT] def bulk_declare hash , & block hash . keys . each do | key | column = Column . new column . colref hash [ key ] if block column . instance_eval ( block ) end @colspec << column . to_hash . merge ( { name : key } ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "read a file and store it internally [CODESPLIT] def read args = { } if args . class == Hash hash = @options . merge ( args ) else puts \"dreader error at #{__callee__}: this function takes a Hash as input\" exit end spreadsheet = Dreader :: Engine . open_spreadsheet ( hash [ :filename ] ) sheet = spreadsheet . sheet ( hash [ :sheet ] || 0 ) @table = Array . new @errors = Array . new first_row = hash [ :first_row ] || 1 last_row = hash [ :last_row ] || sheet . last_row ( first_row .. last_row ) . each do | row_number | r = Hash . new @colspec . each_with_index do | colspec , index | cell = sheet . cell ( row_number , colspec [ :colref ] ) colname = colspec [ :name ] r [ colname ] = Hash . new r [ colname ] [ :row_number ] = row_number r [ colname ] [ :col_number ] = colspec [ :colref ] begin r [ colname ] [ :value ] = value = colspec [ :process ] ? colspec [ :process ] . call ( cell ) : cell rescue => e puts \"dreader error at #{__callee__}: 'process' specification for :#{colname} raised an exception at row #{row_number} (col #{index + 1}, value: #{cell})\" raise e end begin if colspec [ :check ] and not colspec [ :check ] . call ( value ) then r [ colname ] [ :error ] = true @errors << \"dreader error at #{__callee__}: value \\\"#{cell}\\\" for #{colname} at row #{row_number} (col #{index + 1}) does not pass the check function\" else r [ colname ] [ :error ] = false end rescue => e puts \"dreader error at #{__callee__}: 'check' specification for :#{colname} raised an exception at row #{row_number} (col #{index + 1}, value: #{cell})\" raise e end end @table << r end @table end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "show to stdout the first n records we read from the file given the current configuration [CODESPLIT] def debug args = { } if args . class == Hash hash = @options . merge ( args ) else puts \"dreader error at #{__callee__}: this function takes a Hash as input\" exit end # apply some defaults, if not defined in the options hash [ :process ] = true if not hash . has_key? :process # shall we apply the process function? hash [ :check ] = true if not hash . has_key? :check # shall we check the data read? hash [ :n ] = 10 if not hash [ :n ] spreadsheet = Dreader :: Engine . open_spreadsheet ( hash [ :filename ] ) sheet = spreadsheet . sheet ( hash [ :sheet ] || 0 ) puts \"Current configuration:\" @options . each do | k , v | puts \"  #{k}: #{v}\" end puts \"Configuration used by debug:\" hash . each do | k , v | puts \"  #{k}: #{v}\" end n = hash [ :n ] first_row = hash [ :first_row ] || 1 last_row = first_row + n - 1 puts \"  Last row (according to roo): #{sheet.last_row}\" puts \"  Number of rows I will read in this session: #{n} (from #{first_row} to #{last_row})\" ( first_row .. last_row ) . each do | row_number | puts \"Row #{row_number} is:\" r = Hash . new @colspec . each_with_index do | colspec , index | colname = colspec [ :name ] cell = sheet . cell ( row_number , colspec [ :colref ] ) processed_str = \"\" checked_str = \"\" if hash [ :process ] begin processed = colspec [ :process ] ? colspec [ :process ] . call ( cell ) : cell processed_str = \"processed: '#{processed}' (#{processed.class})\" rescue => e puts \"dreader error at #{__callee__}: 'check' specification for :#{colname} raised an exception at row #{row_number} (col #{index + 1}, value: #{cell})\" raise e end end if hash [ :check ] begin processed = colspec [ :process ] ? colspec [ :process ] . call ( cell ) : cell check = colspec [ :check ] ? colspec [ :check ] . call ( processed ) : \"no check specified\" checked_str = \"checked: '#{check}'\" rescue => e puts \"dreader error at #{__callee__}: 'check' specification for #{colname} at row #{row_number} raised an exception (col #{index + 1}, value: #{cell})\" raise e end end puts \"  #{colname} => orig: '#{cell}' (#{cell.class}) #{processed_str} #{checked_str} (column: '#{colspec[:colref]}')\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Provide a config source file path and an exception . [CODESPLIT] def backtrace_lineno_for_config ( file_path , exception ) # For a SyntaxError, we really need to grep it from the # exception message, it really appears to be nowhere else. Ugh. if exception . kind_of? SyntaxError if m = / \\d / . match ( exception . message ) return m [ 1 ] . to_i end end # Otherwise we try to fish it out of the backtrace, first # line matching the config file path. # exception.backtrace_locations exists in MRI 2.1+, which makes # our task a lot easier. But not yet in JRuby 1.7.x, so we got to # handle the old way of having to parse the strings in backtrace too. if ( exception . respond_to? ( :backtrace_locations ) && exception . backtrace_locations && exception . backtrace_locations . length > 0 ) location = exception . backtrace_locations . find do | bt | bt . path == file_path end return location ? location . lineno : nil else # have to parse string backtrace exception . backtrace . each do | line | if line . start_with? ( file_path ) if m = / \\A \\: \\d \\: / . match ( line ) return m [ 1 ] . to_i break end end end # if we got here, we have nothing return nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Extract just the part of the backtrace that is below the config file mentioned . If we can t find the config file in the stack trace we might return empty array . [CODESPLIT] def backtrace_from_config ( file_path , exception ) filtered_trace = [ ] found = false # MRI 2.1+ has exception.backtrace_locations which makes # this a lot easier, but JRuby 1.7.x doesn't yet, so we # need to do it both ways. if ( exception . respond_to? ( :backtrace_locations ) && exception . backtrace_locations && exception . backtrace_locations . length > 0 ) exception . backtrace_locations . each do | location | filtered_trace << location ( found = true and break ) if location . path == file_path end else filtered_trace = [ ] exception . backtrace . each do | line | filtered_trace << line ( found = true and break ) if line . start_with? ( file_path ) end end return found ? filtered_trace : [ ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ruby stdlib queue lacks a drain function we write one . [CODESPLIT] def drain_queue ( queue ) result = [ ] queue_size = queue . size begin queue_size . times do result << queue . deq ( :raise_if_empty ) end rescue ThreadError # Need do nothing, queue was concurrently popped, no biggie end return result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return all nodes in order as an hashalways_use [CODESPLIT] def get_hash ( params = { } , sorted = true ) get_nodes ( sorted ) . map { | n | n . to_hash ( params [ n . name ] ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the string representation of nodes and blocks by updating with given parameters [CODESPLIT] def get_sentence ( params = { } , sorted = true , separator = ' ' ) build_sentence_from_hash ( get_hash ( params , sorted ) ) . select ( :present? ) . join ( separator ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return nodes by sorting option [CODESPLIT] def get_nodes ( sorted = true ) SentenceBuilder :: Helper . to_boolean ( sorted ) ? @nodes . sort_by { | i | i . sort_by_value } : @nodes end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "By parsing each node s hash create a sentence [CODESPLIT] def build_sentence_from_hash ( nodes ) result = [ ] nodes . each do | node | # This node does not appear in params if node [ :current_value ] . nil? if node [ :always_use ] result << node [ :sentence ] end else result << node [ :sentence ] end end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "after calling this action I expect the titles and [CODESPLIT] def read_pages sql = \"SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;\" results = database . query ( sql ) results . each do | row | titles << row [ \"tag\" ] author = authors [ row [ \"user\" ] ] page = Page . new ( { :id => row [ \"id\" ] , :title => row [ \"tag\" ] , :body => row [ \"body\" ] , :markup => :wikka , :latest => row [ \"latest\" ] == \"Y\" , :time => row [ \"time\" ] , :message => row [ \"note\" ] , :author => author , :author_name => row [ \"user\" ] } ) revisions << page end titles . uniq! #revisions.sort! { |a,b| a.time <=> b.time } revisions end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterates over params hash and applies non - empty values as filters [CODESPLIT] def filter ( params ) results = where ( nil ) params . each do | key , value | results = results . public_send ( key , value ) if value . present? end results end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "take an input stream and convert all wikka syntax to markdown syntax [CODESPLIT] def run body migrated_body = body . dup migrated_body . gsub! ( / \\[ \\[ \\S \\| \\] \\] / , '[[\\2|\\1]]' ) migrated_body . gsub! ( / \\[ \\[ \\w \\s \\. \\] \\] / ) do | s | if $1 s = $1 t = $1 . dup t . gsub! ( ' ' , '_' ) t . gsub! ( / \\. / , '' ) s = \"[[#{s}|#{t}]]\" end end migrated_body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets a list of all the sites for the company [CODESPLIT] def sites response = conn . get ( \"#{base_url}/site\" , { } , query_headers ) body = JSON . parse ( response . body ) body . map { | b | Site . new ( b ) } rescue JSON :: ParserError fail QueryError , \"Query Failed! HTTPStatus: #{response.status} - Response: #{body}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns site attributes and history data if an optional query_hash is supplied [CODESPLIT] def site_query ( * args ) response = conn . get ( url_picker ( args ) , { } , query_headers ) if response . body [ 'SiteId' ] || response . body [ 'PointId' ] JSON . parse ( response . body ) else fail QueryError , \"Query Failed! HTTPStatus: #{response.status}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "seconds [CODESPLIT] def move_mouse_randomly x , y = get_cursor_pos # For some reason, x or y returns as nil sometimes if x && y x1 , y1 = x + rand ( 3 ) - 1 , y + rand ( 3 ) - 1 mouse_event ( MOUSEEVENTF_ABSOLUTE , x1 , y1 , 0 , 0 ) puts \"Cursor positon set to #{x1}, #{y1}\" else puts \"X: #{x}, Y: #{y}, last error: #{Win::Error::get_last_error}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Constructor method . Initializes the following : * a url of the source * and the name of the source * a list of currency codes available Fetch medium rate which is calculated based on current transactions in Walutomat [CODESPLIT] def medium_rate regexp = Regexp . new ( \"#{currency_code} / PLN\" ) page . search ( \"//span[@name='pair']\" ) . each do | td | if ( regexp . match ( td . content ) ) return td . next_element . content . to_f end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The hour of the rate [CODESPLIT] def rate_time regexp = Regexp . new ( currency_code ) page . search ( \"//span[@name='pair']\" ) . each do | td | if regexp . match ( td . content ) hour = td . next_element . next_element . content return DateTime . parse ( hour ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assigns output to a file with the given name . Returns the file ; the client is responsible for closing it . [CODESPLIT] def outfile = f io = f . kind_of? ( IO ) ? f : File . new ( f , \"w\" ) @writer . output = io end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a printf format for the given widths for aligning output . To lead lines with zeros ( e . g . 00317 ) the line argument must be a string with leading zeros not an integer . [CODESPLIT] def set_widths file , line , method @format = LocationFormat . new file : file , line : line , method : method end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Logs the given message . [CODESPLIT] def log msg = \"\" , obj = nil , level : Level :: DEBUG , classname : nil , & blk log_frames msg , obj , classname : classname , level : level , nframes : 0 , blk end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns all available options fields and their respective label as a Hash . [CODESPLIT] def options option_hash = { } my_labels = option_names my_inputs = option_fields my_labels . count . times do | index | option_hash [ my_labels [ index ] ] = my_inputs [ index ] end option_hash end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Selects the given option ( s ) and deselects all other ones . This can not be done with radio buttons however as they cannot be deselected . [CODESPLIT] def set ( * wanted_options ) options_to_select = [ wanted_options ] . flatten options_to_deselect = option_names - options_to_select @options = options select ( options_to_select , true ) select ( options_to_deselect , false ) @options = nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the selected options of this OptionGroup . [CODESPLIT] def selected_options selected = [ ] my_labels = option_names inputs . each_with_index do | field , index | selected << my_labels [ index ] if field . checked? end selected end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public methods [CODESPLIT] def action ( data ) data . deep_symbolize_keys! publication = data [ :publication ] channel_options = @ChannelPublications [ publication ] if channel_options model = channel_options [ :model ] model_options = model . ChannelPublications [ publication ] params = data [ :params ] command = data [ :command ] action_params = { publication : publication , model : model , model_options : model_options , options : channel_options , params : params , command : command } case command when \"fetch\" fetch ( action_params ) when \"create\" create ( action_params ) when \"update\" update ( action_params ) when \"destroy\" destroy ( action_params ) end else response = { publication : publication , msg : 'error' , command : command , error : \"Stream for publication '#{publication}' does not exist in channel '#{self.channel_name}'.\" } # Send error notification to the client transmit response end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Streams notification for ActiveRecord model changes [CODESPLIT] def stream_notifications_for ( model , options = { } ) # Default publication options options = { publication : model . model_name . name , cache : false , model_options : { } , scope : :all } . merge ( options ) . merge ( params . deep_symbolize_keys ) # These options cannot be overridden options [ :model ] = model publication = options [ :publication ] # Checks if the publication already exists in the channel if not @ChannelPublications . include? ( publication ) # Sets channel options @ChannelPublications [ publication ] = options # Checks if model already includes notification callbacks if ! model . respond_to? :ChannelPublications model . send ( 'include' , ActionCableNotifications :: Model ) end # Sets broadcast options if they are not already present in the model if not model . ChannelPublications . key? publication model . broadcast_notifications_from publication , options [ :model_options ] else # Reads options configuracion from model options [ :model_options ] = model . ChannelPublications [ publication ] end # Start streaming stream_from publication , coder : ActiveSupport :: JSON do | packet | packet . merge! ( { publication : publication } ) transmit_packet ( packet , options ) end # XXX: Transmit initial data end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Transmits packets to connected client [CODESPLIT] def transmit_packet ( packet , options = { } ) # Default options options = { cache : false } . merge ( options ) packet = packet . as_json . deep_symbolize_keys if validate_packet ( packet , options ) if options [ :cache ] == true if update_cache ( packet ) transmit packet end else transmit packet end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TODO should exist another method passed! for tag_name_required ? [CODESPLIT] def run! ( hash = nil ) @state = :not_checked #@field.each do |field| #if @state == :passed #  break #end case @setting when :tag_name_required , :tag_name_suggested content = nil if hash #puts \"#{@depth.inspect} - required: #{required.inspect}\" found = false self . tag_names . each do | key | if hash . keys . include? ( key ) found = true break end end if found @state = :passed else if @setting == :tag_name_required #puts \"hash: #{hash.inspect}\" #puts \"self.tag_names: #{self.tag_names.inspect}\" @state = :not_passed end end else @state = :passed end when :content_values if hash found = false self . tag_names . each do | key | content = hash [ key ] #puts content #puts @possible_values.inspect if @possible_values . include? ( content ) found = true break end end if found @state = :passed else @state = :not_passed end end #when :not_blank #  if hash.has_key?(field) and !hash[field].to_s.empty? #    @state = :passed #  else #    @state = :not_passed #  end end #end @state end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns true if strict ancestor of [CODESPLIT] def strict_ancestor_of? ( block_start ) block_start && block_start . parent && ( self == block_start . parent || strict_ancestor_of? ( block_start . parent ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "FIXME : This currently depends on series being numbered sequentially and being arranged in that order in the EAD XML . [CODESPLIT] def get_series c01_series = @dsc . xpath ( \".//xmlns:c01[@level='series']\" ) if c01_series and ! c01_series . empty? c01_series . each_with_index do | c01 , i | if mead . series . to_i == i + 1 @series = c01 end end else @series = @dsc end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "memoized hash of built in object ids [CODESPLIT] def built_in_object_ids @built_in_object_ids ||= Hash . new do | hash , key | hash [ key ] = where ( built_in_key : key ) . pluck ( :id ) . first end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the time for this rate ( based on the information on the website ) [CODESPLIT] def rate_time regexp = Regexp . new ( / \\d \\d \\d \\d \\d \\d \\d \\d / ) page . search ( '//p[@class=\"nag\"]' ) . each do | p | p . search ( 'b' ) . each do | b | if regexp . match ( b . content ) return DateTime . strptime ( b . content , \"%Y-%m-%d\" ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "See Stevens s Advanced Programming in the UNIX Environment chapter 13 [CODESPLIT] def daemonize ( safe = true ) $stdin . reopen '/dev/null' # Fork and have the parent exit. # This makes the shell or boot script think the command is done. # Also, the child process is guaranteed not to be a process group # leader (a prerequisite for setsid next) exit if fork # Call setsid to create a new session. This does three things: # - The process becomes a session leader of a new session # - The process becomes the process group leader of a new process group # - The process has no controlling terminal Process . setsid # Fork again and have the parent exit. # This guarantes that the daemon is not a session leader nor can # it acquire a controlling terminal (under SVR4) exit if fork unless safe :: Dir . chdir ( '/' ) :: File . umask ( 0000 ) end cfg_defaults = Clacks :: Configurator :: DEFAULTS cfg_defaults [ :stdout_path ] ||= \"/dev/null\" cfg_defaults [ :stderr_path ] ||= \"/dev/null\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Redirect file descriptors inherited from the parent . [CODESPLIT] def reopen_io ( io , path ) io . reopen ( :: File . open ( path , \"ab\" ) ) if path io . sync = true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read the working pid from the pid file . [CODESPLIT] def running? ( path ) wpid = :: File . read ( path ) . to_i return if wpid <= 0 Process . kill ( 0 , wpid ) wpid rescue Errno :: EPERM , Errno :: ESRCH , Errno :: ENOENT # noop end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the pid . [CODESPLIT] def write_pid ( pid ) :: File . open ( pid , 'w' ) { | f | f . write ( \"#{Process.pid}\" ) } at_exit { :: File . delete ( pid ) if :: File . exist? ( pid ) rescue nil } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "take an input stream and convert all wikka syntax to markdown syntax [CODESPLIT] def run body body = body . dup body . gsub! ( / / ) { | s | '# ' + $2 } #h1 body . gsub! ( / / ) { | s | '## ' + $2 } #h2 body . gsub! ( / / ) { | s | '### ' + $2 } #h3 body . gsub! ( / / ) { | s | '#### ' + $2 } #h4 body . gsub! ( / \\* \\* \\* \\* / ) { | s | '**' + $2 + '**' } #bold body . gsub! ( / \\/ \\/ \\/ \\/ / ) { | s | '_' + $2 + '_' } #italic #str.gsub!(/(===)(.*?)(===)/) {|s| '`' + $2 + '`'}   #code body . gsub! ( / / ) { | s | '<u>' + $2 + '</u>' } #underline body . gsub! ( / / , '  ' ) #forced linebreak #body.gsub!(/(.*?)(\\n\\t-)(.*?)/) {|s| $1 + $3 }   #list body . gsub! ( / \\t / , '*\\2' ) # unordered list body . gsub! ( / / , '*\\2' ) # unordered list body . gsub! ( / / , '*\\2' ) # unordered list # TODO ordered lists # TODO images: ({{image)(url\\=?)?(.*)(}}) #str.gsub!(/(----)/) {|s| '~~~~'}   #seperator body . gsub! ( / \\[ \\[ \\w \\s \\] \\] / , '[[\\3|\\2]]' ) #body.gsub!(/\\[\\[(\\w+)\\s(.+)\\]\\]/, ' [[\\1 | \\2]] ') # TODO more syntax conversion for links and images body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Perform string escaping for Atom slugs [CODESPLIT] def slug ( string ) string . chars . to_a . map do | char | decimal = char . unpack ( 'U' ) . join ( '' ) . to_i if decimal < 32 || decimal > 126 || decimal == 37 char = \"%#{char.unpack('H2').join('%').upcase}\" end char end . join ( '' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "If a location is given then extraction can take place [CODESPLIT] def parse_mead ( * args ) parts = @mead . split ( '-' ) args . each_with_index do | field , i | instance_variable_set ( '@' + field , parts [ i ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Intialize a new mixml tool Load XML files [CODESPLIT] def load ( * file_names ) file_names . flatten . each do | file_name | xml = File . open ( file_name , 'r' ) do | file | Nokogiri :: XML ( file ) do | config | if @pretty then config . default_xml . noblanks end end end @documents << Document . new ( file_name , xml ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Save all loaded XML files [CODESPLIT] def save_all output_all do | document , options | File . open ( document . name , 'w' ) do | file | document . xml . write_xml_to ( file , options ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Print all loaded XML files [CODESPLIT] def print_all output_all do | document , options | if @documents . size > 1 then puts '-' * document . name . length puts document . name puts '-' * document . name . length end puts document . xml . to_xml ( options ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform work on a list of XML files [CODESPLIT] def work ( * file_names , & block ) remove_all file_names . each do | file_name | load ( file_name ) if not block . nil? then execute ( block ) end flush remove_all end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Select nodes using an XPath expression and execute DSL commands for these nodes [CODESPLIT] def xpath ( * paths , & block ) nodesets = [ ] process do | xml | nodesets << xml . xpath ( paths ) end selection = Selection . new ( nodesets ) if block_given? then Docile . dsl_eval ( selection , block ) end selection end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Select nodes using CSS selectors and execute DSL commands for these nodes [CODESPLIT] def css ( * selectors , & block ) nodesets = [ ] process do | xml | nodesets << xml . css ( selectors ) end selection = Selection . new ( nodesets ) if block_given? then Docile . dsl_eval ( selection , block ) end selection end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute a script or a block [CODESPLIT] def execute ( program = nil , & block ) if not program . nil? then instance_eval ( program ) end if not block . nil? then Docile . dsl_eval ( self , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Execute block for each node [CODESPLIT] def with_nodes ( selection ) selection . nodesets . each do | nodeset | nodeset . each do | node | yield node end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Tag support [CODESPLIT] def tag_filter ( model = nil , filters = nil , scope = :tagged_with ) model ||= controller_name . singularize . camelize . constantize filters ||= model . top_tags render 'layouts/tag_filter' , :filters => filters , :scope => scope end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decommentifies the supplied input . [CODESPLIT] def decommentify input output = input . dup # Remove multiline comments: output . gsub! ( / #{ Regexp . quote @block_comment_start } #{ Regexp . quote @block_comment_end } /m , \"\" ) # Remove inline comments: output . gsub! ( / #{ Regexp . quote @inline_comment_delimiter } / , \"\" ) return output . lines . map ( :strip ) . join ( $/ ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Tagifies the supplied input . [CODESPLIT] def tagify input output = input . dup raise StandardError , \"@tags is empty!\" if @tags . empty? #improve on this @tags . each { | key , value | output . gsub! ( tag_start . to_s + key . to_s + tag_end . to_s , value . to_s ) } return output end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Searches for the specified label and returns the form field belonging to it identified by the for attribute of the label . Alternatively you may pass a Watir :: Label . @param [ String Watir :: Label ] label the label for which to find the form field . @param [ Watir :: Element ] start_node the node where to start searching for the label . @param [ Boolean ] placeholder whether to handle label as Watir :: Label or as placeholder attribute for an input field . @param [ Boolean ] id assumes the given label is an HTML ID and searches for it . [CODESPLIT] def field ( label , start_node : nil , placeholder : false , id : false ) start_node ||= self if placeholder start_node . element ( placeholder : label ) . to_subtype elsif id start_node . element ( id : label ) . to_subtype else field_label = label . respond_to? ( :for ) ? label : start_node . label ( text : label ) determine_field ( start_node , field_label ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Fills in the given value ( s ) to the passed attribute . It therefore accepts the same parameters as the #field method . [CODESPLIT] def fill_in ( label , value , start_node : nil , placeholder : false , id : false ) field ( label , start_node : start_node , placeholder : placeholder , id : id ) . set ( value ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns the current value of the specified form field . It therefore accepts the same parameters as the #field method . [CODESPLIT] def value_of ( label , start_node : nil , placeholder : false , id : false ) field ( label , start_node : start_node , placeholder : placeholder , id : id ) . field_value end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns an OptionGroup [CODESPLIT] def option_group ( * args ) selector = if args . first . respond_to? ( :elements ) args . first else extract_selector ( args ) end OptionGroup . new ( self , selector ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "default rake task initializer call this to run a { CommandDefinition } subclass [CODESPLIT] def run_definition ( defin , & block ) command = defin defin . instance_eval ( block ) if block add_command ( command ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a caramelize config file . [CODESPLIT] def execute ( args ) # create dummy config file target_file = @config_file . nil? ? \"caramel.rb\" : @config_file FileUtils . cp ( File . dirname ( __FILE__ ) + \"/../caramel.rb\" , target_file ) if commandparser . verbosity == :normal puts \"Created new configuration file: #{target_file}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new command line interface Runs a script with given name ( token ) and argv inside this CLI instance [CODESPLIT] def run ( script_name , argv , argf = ARGF ) script = script_class_name ( script_name ) . to_class raise ScriptNameError . new ( \"Script #{script_class_name(script_name)} not found\" ) unless script script . new ( script_name , self , argv , argf ) . run end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Registers a workflow relationship and sets up a hook to additional builder methods . [CODESPLIT] def has_machete_workflow_of ( jobs_active_record_relation_symbol ) # yes, this is magic mimicked from http://guides.rubyonrails.org/plugins.html #  and http://yehudakatz.com/2009/11/12/better-ruby-idioms/ cattr_accessor :jobs_active_record_relation_symbol self . jobs_active_record_relation_symbol = jobs_active_record_relation_symbol # separate modules to group common methods for readability purposes # both builder methods and status methods need the jobs relation so # we include that first self . send :include , OscMacheteRails :: Workflow :: JobsRelation self . send :include , OscMacheteRails :: Workflow :: BuilderMethods self . send :include , OscMacheteRails :: Workflow :: StatusMethods end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Do the actual work of building the formatted output . <br > Parameters * src - The source object being formatted . * format_spec_str - The format specification string . [CODESPLIT] def do_format ( src , format_spec_str ) spec_info = SpecInfo . new ( src , \"\" , self ) due_process ( spec_info , format_spec_str ) do | format | spec_info . do_format ( format ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Do the actual work of parsing the formatted input . <br > Parameters * src - The source string being parsed . * dst - The class of the object being created . * parse_spec_str - The format specification string . [CODESPLIT] def do_parse ( src , dst , parse_spec_str ) spec_info = SpecInfo . new ( src , dst , self ) due_process ( spec_info , parse_spec_str ) do | format | spec_info . do_parse ( format ) end ensure @unparsed = spec_info . src end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Do the actual work of parsing the formatted input . <br > Parameters * spec_info - The state of the process . * spec_str - The format specification string . * block - A code block performed for each format specification . [CODESPLIT] def due_process ( spec_info , spec_str ) format_spec = get_spec ( spec_str ) spec_info . instance_exec ( self [ :before ] ) format_spec . specs . each do | format | break if yield ( format ) == :break end spec_info . instance_exec ( self [ :after ] ) spec_info . dst end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "= begin This wants to be a magic configuration loader who looks for configuration automatically in many places like : [CODESPLIT] def load_auto_conf ( confname , opts = { } ) libver = '1.1' dirs = opts . fetch :dirs , [ '.' , '~' , '/etc/' , '/etc/ric/auto_conf/' ] file_patterns = opts . fetch :file_patterns , [ \".#{confname}.yml\" , \"#{confname}/conf.yml\" ] sample_hash = opts . fetch :sample_hash , { 'load_auto_conf' => \"please add an :sample_hash to me\" , :anyway => \"I'm in #{__FILE__}\" } verbose = opts . fetch :verbose , true puts \"load_auto_conf('#{confname}') v#{libver} start..\" if verbose dirs . each { | d | dir = File . expand_path ( d ) deb \"DIR: #{dir}\" file_patterns . each { | fp | # if YML exists return the load.. file = \"#{dir}/#{fp}\" deb \" - FILE: #{file}\" if File . exists? ( file ) puts \"Found! #{green file}\" yaml = YAML . load ( File . read ( file ) ) puts \"load_auto_conf('#{confname}', v#{libver}) found: #{green yaml}\" if verbose return yaml # in the future u can have a host based autoconf! Yay! end } } puts \"Conf not found. Try this:\\n---------------------------\\n$ cat > ~/#{file_patterns.first}\\n#{yellow \"#Creatd by ric.rb:load_auto_conf()\\n\" +sample_hash.to_yaml}\\n---------------------------\\n\" raise \"LoadAutoConf: configuration not found for '#{confname}'!\" return sample_hash end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Must be called within a mutex synchronize [CODESPLIT] def check_retry if @finished_publishing && @pending_hash . empty? && @exception_count > 0 && ( @retry || @auto_retry ) # If we're just doing auto_retry but nothing succeeded last time, then don't run again return if ! @retry && @auto_retry && @exception_count == @exceptions_per_run . last Qwirk . logger . info \"#{self}: Retrying exception records, exception count = #{@exception_count}\" @exceptions_per_run << @exception_count @exception_count = 0 @finished_publishing = false @fail_thread = Thread . new ( @exceptions_per_run . last ) do | count | begin java . lang . Thread . current_thread . name = \"Qwirk fail task: #{task_id}\" while ! @stopped && ( count > 0 ) && ( object = @fail_consumer . receive ) count -= 1 publish ( object ) @fail_consumer . acknowledge_message end @finished_publishing = true @pending_hash_mutex . synchronize { check_finish } rescue Exception => e do_stop Qwirk . logger . error \"#{self}: Exception, thread terminating: #{e.message}\\n\\t#{e.backtrace.join(\"\\n\\t\")}\" end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run the mixml command [CODESPLIT] def run program :name , 'mixml' program :version , Mixml :: VERSION program :description , 'XML helper tool' $tool = Mixml :: Tool . new global_option ( '-p' , '--pretty' , 'Pretty print output' ) do | value | $tool . pretty = value end global_option ( '-i' , '--inplace' , 'Replace the processed files with the new files' ) do | value | $tool . save = value $tool . print = ! value end global_option ( '-q' , '--quiet' , 'Do not print nodes' ) do | value | $tool . print = ! value end command :pretty do | c | c . description = 'Pretty print XML files' c . action do | args , options | $tool . pretty = true $tool . work ( args ) end end modify_command :write do | c | c . description = 'Write selected nodes to the console' c . suppress_output = true c . optional_expression = true end select_command :remove do | c | c . description = 'Remove nodes from the XML documents' end modify_command :replace do | c | c . description = 'Replace nodes in the XML documents' end modify_command :append do | c | c . description = 'Append child nodes in the XML documents' end modify_command :rename do | c | c . description = 'Rename nodes in the XML documents' end modify_command :value do | c | c . description = 'Set node values' end command :execute do | c | c . description = 'Execute script on the XML documents' c . option '-s' , '--script STRING' , String , 'Script file to execute' c . option '-e' , '--expression STRING' , String , 'Command to execute' c . action do | args , options | script = options . expression || File . read ( options . script ) $tool . work ( args ) do execute ( script ) end end end run! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List current tasks [CODESPLIT] def list entities = @db . list out entities = entities . is_a? ( Fixnum ) ? @db . list [ 0 ... entities ] : entities entities . reject { | e | e [ :status ] == :removed } . each_with_index do | e , i | out \" [#{i}]\" . blue + \"#{e.sticky?? \" + \".bold : \"   \"}\" + e [ :title ] . underline + \" #{e[:tags].join(' ')}\" . cyan end . tap do | list | out \" ...\" if @db . list . length > entities . length && ! entities . length . zero? out \"  there are no koi in the water\" . green if list . size . zero? end out entities end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Show task history [CODESPLIT] def log @db . map do | entity | Entity :: Status . map do | status | { title : entity [ :title ] , action : status , time : entity [ :\" #{ status } \" ] . strftime ( \"%Y/%m/%d %H:%m\" ) } if entity [ :\" #{ status } \" ] end . compact end . flatten . sort_by { | e | e [ :time ] } . reverse . each do | entry | out \"#{entry[:time].blue} #{entry[:action].to_s.bold} #{entry[:title].underline}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Handle things like self . removed? [CODESPLIT] def method_missing meth , * args , & blk if meth . to_s . end_with? ( '?' ) && Status . include? ( s = meth . to_s . chop . to_sym ) self [ :status ] == s else super end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a GET request options hash should contain query parameters [CODESPLIT] def v3_get ( path , options = { } ) # Create request parameters get_params = { :method => \"get\" } get_params [ :params ] = options unless options . empty? # Send request (with caching) v3_do_request ( get_params , path , :cache => true ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a PUT request options hash should contain request body parameters [CODESPLIT] def v3_put ( path , options = { } ) # Expire cached objects from parent on down expire_matching \"#{parent_path(path)}.*\" # Create request parameters put_params = { :method => \"put\" , :body => options [ :body ] ? options [ :body ] : form_encode ( options ) } if options [ :content_type ] put_params [ :headers ] = { :' ' => content_type ( options [ :content_type ] ) } end # Request v3_do_request ( put_params , path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform a POST request options hash should contain request body parameters It can also contain a : returnobj parameter which will cause a full reponse object to be returned instead of just the body [CODESPLIT] def v3_post ( path , options = { } ) # Expire cached objects from here on down expire_matching \"#{raw_path(path)}.*\" # Get 'return full response object' flag return_obj = options . delete ( :returnobj ) || false # Create request parameters post_params = { :method => \"post\" , :body => form_encode ( options ) } if options [ :content_type ] post_params [ :headers ] = { :' ' => content_type ( options [ :content_type ] ) } end # Request v3_do_request ( post_params , path , :return_obj => return_obj ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrap up parameters into a request and execute it [CODESPLIT] def v3_do_request ( params , path , options = { } ) req = Typhoeus :: Request . new ( \"https://#{v3_hostname}#{path}\" , v3_defaults . merge ( params ) ) response = do_request ( req , :xml , options ) options [ :return_obj ] == true ? response : response . body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds token with specified timestamp to the place . Any callbacks defined for places will be fired . [CODESPLIT] def add ( token , timestamp = nil ) @net . call_callbacks ( :place , :add , Event . new ( @name , [ token ] , @net ) ) unless @net . nil? if timestamp . nil? @marking . add token else @marking . add token , timestamp end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "the first element of ARGV should be a subcommand which maps to a class in spanx / cli / [CODESPLIT] def run ( args = ARGV ) @args = args validate! Spanx :: CLI . subclass_class ( args . shift ) . new . run ( args ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "legal_assesment [CODESPLIT] def legal_assesment ( subject ) Lawyer . new do | lawyer | unless subject . respond_to? method lawyer . unsatisfied! \"Expected subject to respond to method '#{method}'\" end if @block || expected_response response_when_called ( subject , method , args ) . tap do | response_when_called | if @block unless @block . call ( response_when_called ) lawyer . unsatisfied! \"Block did not respond with 'true' for method #{method}\" end end if expected_response unless response_when_called == expected_response lawyer . unsatisfied! \"Expected method #{method} to return #{expected_response} but got #{response_when_called}\" end end end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ensure valid credentials either by restoring from the saved credentials files or intitiating an OAuth2 authorization . If authorization is required the user s default browser will be launched to approve the request . [CODESPLIT] def authorize client_id = Google :: Auth :: ClientId . from_file ( CLIENT_SECRETS_PATH ) token_store = Google :: Auth :: Stores :: FileTokenStore . new ( file : CREDENTIALS_PATH ) authorizer = Google :: Auth :: UserAuthorizer . new ( client_id , SCOPE , token_store ) user_id = 'default' credentials = authorizer . get_credentials ( user_id ) if credentials . nil? url = authorizer . get_authorization_url ( base_url : OOB_URI ) puts 'Open the following URL in the browser and enter the ' \"resulting code after authorization:\\n\" + url code = STDIN . gets credentials = authorizer . get_and_store_credentials_from_code ( user_id : user_id , code : code , base_url : OOB_URI ) end credentials end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET data from the API passing in a hash of parameters [CODESPLIT] def get ( path , data = { } ) # Allow format override format = data . delete ( :format ) || @format # Add parameters to URL query string get_params = { :method => \"get\" , :verbose => DEBUG } get_params [ :params ] = data unless data . empty? # Create GET request get = Typhoeus :: Request . new ( \"#{protocol}#{@server}#{path}\" , get_params ) # Send request do_request ( get , format , :cache => true ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST to the AMEE API passing in a hash of values [CODESPLIT] def post ( path , data = { } ) # Allow format override format = data . delete ( :format ) || @format # Clear cache expire_matching \"#{raw_path(path)}.*\" # Extract return unit params query_params = { } query_params [ :returnUnit ] = data . delete ( :returnUnit ) if data [ :returnUnit ] query_params [ :returnPerUnit ] = data . delete ( :returnPerUnit ) if data [ :returnPerUnit ] # Create POST request post_params = { :verbose => DEBUG , :method => \"post\" , :body => form_encode ( data ) } post_params [ :params ] = query_params unless query_params . empty? post = Typhoeus :: Request . new ( \"#{protocol}#{@server}#{path}\" , post_params ) # Send request do_request ( post , format ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST to the AMEE API passing in a string of data [CODESPLIT] def raw_post ( path , body , options = { } ) # Allow format override format = options . delete ( :format ) || @format # Clear cache expire_matching \"#{raw_path(path)}.*\" # Create POST request post = Typhoeus :: Request . new ( \"#{protocol}#{@server}#{path}\" , :verbose => DEBUG , :method => \"post\" , :body => body , :headers => { :' ' => options [ :content_type ] || content_type ( format ) } ) # Send request do_request ( post , format ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "PUT to the AMEE API passing in a hash of data [CODESPLIT] def put ( path , data = { } ) # Allow format override format = data . delete ( :format ) || @format # Clear cache expire_matching \"#{parent_path(path)}.*\" # Extract return unit params query_params = { } query_params [ :returnUnit ] = data . delete ( :returnUnit ) if data [ :returnUnit ] query_params [ :returnPerUnit ] = data . delete ( :returnPerUnit ) if data [ :returnPerUnit ] # Create PUT request put_params = { :verbose => DEBUG , :method => \"put\" , :body => form_encode ( data ) } put_params [ :params ] = query_params unless query_params . empty? put = Typhoeus :: Request . new ( \"#{protocol}#{@server}#{path}\" , put_params ) # Send request do_request ( put , format ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "PUT to the AMEE API passing in a string of data [CODESPLIT] def raw_put ( path , body , options = { } ) # Allow format override format = options . delete ( :format ) || @format # Clear cache expire_matching \"#{parent_path(path)}.*\" # Create PUT request put = Typhoeus :: Request . new ( \"#{protocol}#{@server}#{path}\" , :verbose => DEBUG , :method => \"put\" , :body => body , :headers => { :' ' => options [ :content_type ] || content_type ( format ) } ) # Send request do_request ( put , format ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Post to the sign in resource on the API so that all future requests are signed [CODESPLIT] def authenticate # :x_amee_source = \"X-AMEE-Source\".to_sym request = Typhoeus :: Request . new ( \"#{protocol}#{@server}/auth/signIn\" , :method => \"post\" , :verbose => DEBUG , :headers => { :Accept => content_type ( :xml ) , } , :body => form_encode ( :username => @username , :password => @password ) ) hydra . queue ( request ) hydra . run response = request . response @auth_token = response . headers_hash [ 'AuthToken' ] d { request . url } d { response . code } d { @auth_token } connection_failed if response . code == 0 unless authenticated? raise AMEE :: AuthFailed . new ( \"Authentication failed. Please check your username and password. (tried #{@username},#{@password})\" ) end # Detect API version if response . body . is_json? @version = JSON . parse ( response . body ) [ \"user\" ] [ \"apiVersion\" ] . to_f elsif response . body . is_xml? @version = REXML :: Document . new ( response . body ) . elements [ 'Resources' ] . elements [ 'SignInResource' ] . elements [ 'User' ] . elements [ 'ApiVersion' ] . text . to_f else @version = 1.0 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "run each request through some basic error checking and if needed log requests [CODESPLIT] def response_ok? ( response , request ) # first allow for debugging d { request . object_id } d { request } d { response . object_id } d { response . code } d { response . headers_hash } d { response . body } case response . code . to_i when 502 , 503 , 504 raise AMEE :: ConnectionFailed . new ( \"A connection error occurred while talking to AMEE: HTTP response code #{response.code}.\\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\" ) when 408 raise AMEE :: TimeOut . new ( \"Request timed out.\" ) when 404 raise AMEE :: NotFound . new ( \"The URL was not found on the server.\\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\" ) when 403 raise AMEE :: PermissionDenied . new ( \"You do not have permission to perform the requested operation.\\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\\n#{request.body}\\Response: #{response.body}\" ) when 401 authenticate return false when 400 if response . body . include? \"would have resulted in a duplicate resource being created\" raise AMEE :: DuplicateResource . new ( \"The specified resource already exists. This is most often caused by creating an item that overlaps another in time.\\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\\n#{request.body}\\Response: #{response.body}\" ) else raise AMEE :: BadRequest . new ( \"Bad request. This is probably due to malformed input data.\\nRequest: #{request.method.upcase} #{request.url.gsub(request.host, '')}\\n#{request.body}\\Response: #{response.body}\" ) end when 200 , 201 , 204 return response when 0 connection_failed end # If we get here, something unhandled has happened, so raise an unknown error. raise AMEE :: UnknownError . new ( \"An error occurred while talking to AMEE: HTTP response code #{response.code}.\\nRequest: #{request.method.upcase} #{request.url}\\n#{request.body}\\Response: #{response.body}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrapper for sending requests through to the API . Takes care of making sure requests authenticated and if set attempts to retry a number of times set when initialising the class [CODESPLIT] def do_request ( request , format = @format , options = { } ) # Is this a v3 request? v3_request = request . url . include? ( \"/#{v3_hostname}/\" ) # make sure we have our auth token before we start # any v1 or v2 requests if ! @auth_token && ! v3_request d \"Authenticating first before we hit #{request.url}\" authenticate end request . headers [ 'Accept' ] = content_type ( format ) # Set AMEE source header if set request . headers [ 'X-AMEE-Source' ] = @amee_source if @amee_source # path+query string only (split with an int limits the number of splits) path_and_query = '/' + request . url . split ( '/' , 4 ) [ 3 ] if options [ :cache ] # Get response with caching response = cache ( path_and_query ) { run_request ( request , :xml ) } else response = run_request ( request , :xml ) end response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "run request . Extracted from do_request to make cache code simpler [CODESPLIT] def run_request ( request , format ) # Is this a v3 request? v3_request = request . url . include? ( \"/#{v3_hostname}/\" ) # Execute with retries retries = [ 1 ] * @retries begin begin d \"Queuing the request for #{request.url}\" add_authentication_to ( request ) if @auth_token && ! v3_request hydra . queue request hydra . run # Return response if OK end while ! response_ok? ( request . response , request ) # Store updated authToken @auth_token = request . response . headers_hash [ 'AuthToken' ] return request . response rescue AMEE :: ConnectionFailed , AMEE :: TimeOut => e if delay = retries . shift sleep delay retry else raise end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create and return a new timed place for this model . [CODESPLIT] def timed_place ( name , keys = { } ) place = create_or_find_place ( name , keys , TimedPlace ) @timed_places [ place ] = true place end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create and return new transition for this model . + name + identifies transition in the net . [CODESPLIT] def transition ( name ) t = find_transition name if t . nil? t = Transition . new name , self @transitions << t end t end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Starts simulation of this net . [CODESPLIT] def sim @stopped = catch :stop_simulation do begin fired = fire_transitions advanced = move_clock_to find_next_time end while fired || advanced end @stopped = false if @stopped == nil rescue StandardError => e raise SimulationError . new ( e ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Defines new callback for this net . + what + can be + : transition + + : place + or + : clock + . Transition callbacks are fired when transitions are fired place callbacks when place marking changes clock callbacks when clock is moved . + tag + for transition and clock callback can be + : before + or + : after + for place can be + : add + or + : remove + . It defines when the callbacks fill be fired . If omitted it will be called for both cases . [CODESPLIT] def cb_for ( what , tag = nil , & block ) if what == :transition cb_for_transition tag , block elsif what == :place cb_for_place tag , block elsif what == :clock cb_for_clock tag , block else raise InvalidCallback . new \"Don't know how to add callback for #{what}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : Calls callbacks for internal use . [CODESPLIT] def call_callbacks ( what , tag , * params ) @callbacks [ what ] [ tag ] . each do | block | block . call tag , params end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add output arc to the + place + . + block + is the arc s expresstion it will be called while firing transition . Value returned from the block will be put in output place . The block gets + binding + and + clock + values . + binding + is a hash with names of input places as keys nad tokens as values . [CODESPLIT] def output ( place , & block ) raise \"This is not a Place object!\" unless place . kind_of? Place raise \"Tried to define output arc without expression! Block is required!\" unless block_given? @outputs << OutputArc . new ( place , block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fire this transition if possible returns true if fired false otherwise [CODESPLIT] def fire ( clock = 0 ) # Marking is shuffled each time before it is # used so here we can take first found binding mapping = Enumerator . new do | y | get_sentry . call ( input_markings , clock , y ) end . first return false if mapping . nil? tcpn_binding = TCPNBinding . new mapping , input_markings call_callbacks :before , Event . new ( @name , tcpn_binding , clock , @net ) tokens_for_outputs = @outputs . map do | o | o . block . call ( tcpn_binding , clock ) end mapping . each do | place_name , token | unless token . kind_of? Token t = if token . instance_of? Array token else [ token ] end t . each do | t | unless t . kind_of? Token raise InvalidToken . new ( \"#{t.inspect} put by sentry for transition `#{name}` in binding for `#{place_name}`\" ) end end end deleted = find_input ( place_name ) . delete ( token ) if deleted . nil? raise InvalidToken . new ( \"#{token.inspect} put by sentry for transition `#{name}` does not exists in `#{place_name}`\" ) end end @outputs . each do | o | token = tokens_for_outputs . shift o . place . add token unless token . nil? end call_callbacks :after , Event . new ( @name , mapping , clock , @net ) true rescue InvalidToken raise rescue RuntimeError => e raise FiringError . new ( self , e ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Process text with remote web - service [CODESPLIT] def send_request ( text ) begin request = Net :: HTTP :: Post . new ( @url . path , { 'Content-Type' => 'text/xml' , 'SOAPAction' => '\"http://typograf.artlebedev.ru/webservices/ProcessText\"' } ) request . body = form_xml ( text , @options ) response = Net :: HTTP . new ( @url . host , @url . port ) . start do | http | http . request ( request ) end rescue StandardError => exception raise NetworkError . new ( exception . message , exception . backtrace ) end if ! response . is_a? ( Net :: HTTPOK ) raise NetworkError , \"#{response.code}: #{response.message}\" end if RESULT =~ response . body body = $1 . gsub ( / / , '>' ) . gsub ( / / , '<' ) . gsub ( / / , '&' ) body . force_encoding ( \"UTF-8\" ) . chomp else raise NetworkError , \"Can't match result #{response.body}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Install rubygems and the librarian - puppet gem onto each host [CODESPLIT] def install_librarian ( opts = { } ) # Check for 'librarian_version' option librarian_version = opts [ :librarian_version ] ||= nil hosts . each do | host | install_package host , 'rubygems' install_package host , 'git' if librarian_version on host , \"gem install --no-ri --no-rdoc librarian-puppet -v '#{librarian_version}'\" else on host , 'gem install --no-ri --no-rdoc librarian-puppet' end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy the module under test to a temporary directory onto the host and execute librarian - puppet to install dependencies into the distmoduledir . [CODESPLIT] def librarian_install_modules ( directory , module_name ) hosts . each do | host | sut_dir = File . join ( '/tmp' , module_name ) scp_to host , directory , sut_dir on host , \"cd #{sut_dir} && librarian-puppet install --clean --verbose --path #{host['distmoduledir']}\" puppet_module_install ( :source => directory , :module_name => module_name ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method returns a single crisis . [CODESPLIT] def get_crisis ( identifier , params = nil ) return nil if identifier . nil? or identifier . empty? endpoint = \"/v1/crises/#{identifier}.json?auth_token=#{@auth_token}\" endpoint += \"&#{URI.encode_www_form params}\" if params response = self . get ( endpoint ) Sigimera :: Crisis . new JSON . parse response . body if response and response . body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method returns statistic information about the crises . [CODESPLIT] def get_crises_stat response = self . get ( \"/v1/stats/crises.json?auth_token=#{@auth_token}\" ) JSON . parse response . body if response and response . body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method returns statistic information about user . [CODESPLIT] def get_user_stat response = self . get ( \"/v1/stats/users.json?auth_token=#{@auth_token}\" ) JSON . parse response . body if response and response . body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "src can be IO or String or anything that responds to : read or : unpack [CODESPLIT] def read src , size = nil size ||= const_get 'SIZE' data = if src . respond_to? ( :read ) src . read ( size ) . to_s elsif src . respond_to? ( :unpack ) src else raise \"[?] don't know how to read from #{src.inspect}\" end if data . size < size $stderr . puts \"[!] #{self.to_s} want #{size} bytes, got #{data.size}\" end new ( data . unpack ( const_get ( 'FORMAT' ) ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "XmlDocument . new () XmlDeclarationNode create_xml_declaration ( string version string encoding ) Returns a node that will appear at the beginning of the document as : <?xml version = [ ver ] encoding = [ enc ] ? > The node must still be added to the parent ( root ) node with XmlNode#append_child . [CODESPLIT] def create_xml_declaration ( version , encoding ) declNode = XmlDeclarationNode . new ( ) { @attributes << XmlAttribute . new ( ) { @name = 'version' ; @value = version } @attributes << XmlAttribute . new ( ) { @name = 'encoding' ; @value = encoding } } declNode . xml_document = self declNode end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "XmlAttribute create_attribute ( string name string val = ) Returns an XmlAttribute . Append to the desired element with XmlElement#append_attribute . [CODESPLIT] def create_attribute ( name , value = '' ) attr = XmlAttribute . new ( ) { @name = name @value = value } attr . xml_document = self attr end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "void write_nodes ( XmlTextWriter writer XmlNodes [] nodes ) [CODESPLIT] def write_nodes ( writer , nodes ) nodes . each_with_index do | node , idx | # write xml declaration if it exists.\r # TODO: Should throw somewhere if this isn't the first node.\r if node . is_a? ( XmlDeclarationNode ) writer . write ( '<?xml' ) write_attributes ( writer , node ) writer . write ( '?>' ) writer . new_line ( ) elsif node . is_a? ( XmlFragment ) # if it's a fragment, just write the fragment, which is expected to be a string.\r writer . write_fragment ( node . text ) else # begin element tag and attributes\r writer . write ( '<' + node . name ) write_attributes ( writer , node ) # if inner text, write it out now.\r if node . inner_text writer . write ( '>' + node . inner_text ) if node . has_child_nodes ( ) write_child_nodes ( writer , node ) end writer . write ( '</' + node . name + '>' ) crlf_if_more_nodes ( writer , nodes , idx ) else # Children are allowed only if there is no inner text.\r if node . has_child_nodes ( ) # close element tag, indent, and recurse.\r writer . write ( '>' ) write_child_nodes ( writer , node ) # close the element\r writer . write ( '</' + node . name + '>' ) crlf_if_more_nodes ( writer , nodes , idx ) else # if no children and no inner text, use the abbreviated closing tag token unless no closing tag is required and unless self closing tags are not allowed.\r if node . html_closing_tag if writer . allow_self_closing_tags writer . write ( '/>' ) else writer . write ( '></' + node . name + '>' ) end else writer . write ( '>' ) end crlf_if_more_nodes ( writer , nodes , idx ) end end end end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write the attribute collection for a node . void write_attributes ( XmlTextWriter writer XmlNode node ) [CODESPLIT] def write_attributes ( writer , node ) if node . attributes . count > 0 # stuff them into an array of strings\r attrs = [ ] node . attributes . each do | attr | # special case:\r # example: <nav class=\"top-bar\" data-topbar>\r if attr . value . nil? attrs << attr . name else attrs << attr . name + '=\"' + attr . value + '\"' end end # separate them with a space\r attr_str = attrs . join ( ' ' ) # requires a leading space as well to separate from the element name.\r writer . write ( ' ' + attr_str ) end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Defines the searchable content in ActiveRecord objects . [CODESPLIT] def posify * source_methods , & block include ModelClassAdditions self . pose_content = proc do text_chunks = source_methods . map { | source | send ( source ) } text_chunks << instance_eval ( block ) if block text_chunks . reject ( :blank? ) . join ( ' ' ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "https : // gist . github . com / hilotter / 6a4c356499b55e8eaf9a / [CODESPLIT] def base64_conversion ( uri_str , filename = 'base64' ) image_data = split_base64 ( uri_str ) image_data_string = image_data [ :data ] image_data_binary = Base64 . decode64 ( image_data_string ) temp_img_file = Tempfile . new ( filename ) temp_img_file . binmode temp_img_file << image_data_binary temp_img_file . rewind img_params = { :filename => \"#{filename}\" , :type => image_data [ :type ] , :tempfile => temp_img_file } ActionDispatch :: Http :: UploadedFile . new ( img_params ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new HashMarking with specified keys . At least one key must be specified . The keys are used to store tokens in Hashes -- one hash for each key . Thus finding tokens by the keys is fast . [CODESPLIT] def each ( key = nil , value = nil ) return enum_for ( :each , key , value ) unless block_given? return if empty? list_for ( key , value ) . lazy_shuffle do | token | yield clone token end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates new token of the + object + and adds it to the marking . Objects added to the marking are deep - cloned so you can use them without fear to interfere with TCPN simulation . But have it in mind! If you put a large object with a lot of references in the marking it will significanntly slow down simulation and increase memory usage . [CODESPLIT] def add ( objects ) unless objects . kind_of? Array objects = [ objects ] end objects . each do | object | value = object if object . instance_of? Hash value = object [ :val ] end add_token prepare_token ( value ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deletes the + token + from the marking . To do it you must first find the token in the marking . [CODESPLIT] def delete ( tokens ) unless tokens . instance_of? Array tokens = [ tokens ] end removed = tokens . map do | token | validate_token! ( token ) delete_token ( token ) end if removed . size == 1 removed . first else removed end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a JOIN to the given expression . [CODESPLIT] def add_joins arel @query . joins . inject ( arel ) do | memo , join_data | add_join memo , join_data end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds the WHERE clauses from the given query to the given arel construct . [CODESPLIT] def add_wheres arel @query . where . inject ( arel ) { | memo , where | memo . where where } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Truncates the result set based on the : limit parameter in the query . [CODESPLIT] def limit_ids result return unless @query . has_limit? result . each do | clazz , ids | result [ clazz ] = ids . slice 0 , @query . limit end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts the ids to classes if the user wants classes . [CODESPLIT] def load_classes result return if @query . ids_requested? result . each do | clazz , ids | if ids . size > 0 result [ clazz ] = clazz . where ( id : ids ) if @query . has_select result [ clazz ] = result [ clazz ] . select ( @query . options [ :select ] ) end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Merges the given posable object ids for a single query word into the given search result . Helper method for : search_words . [CODESPLIT] def merge_search_result_word_matches result , class_name , ids if result . has_key? class_name result [ class_name ] = result [ class_name ] & ids else result [ class_name ] = ids end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Performs a complete search . Clients should use : results to perform a search since it caches the results . [CODESPLIT] def search { } . tap do | result | search_words . each do | class_name , ids | result [ class_name . constantize ] = ids end limit_ids result load_classes result end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds all matching ids for a single word of the search query . [CODESPLIT] def search_word word empty_result . tap do | result | data = Assignment . joins ( :word ) . select ( 'pose_assignments.posable_id, pose_assignments.posable_type' ) . where ( 'pose_words.text LIKE ?' , \"#{word}%\" ) . where ( 'pose_assignments.posable_type IN (?)' , @query . class_names ) data = add_joins data data = add_wheres data Assignment . connection . select_all ( data . to_sql ) . each do | pose_assignment | result [ pose_assignment [ 'posable_type' ] ] << pose_assignment [ 'posable_id' ] . to_i end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns all matching ids for all words of the search query . [CODESPLIT] def search_words { } . tap do | result | @query . query_words . each do | query_word | search_word ( query_word ) . each do | class_name , ids | merge_search_result_word_matches result , class_name , ids end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Deprecated and Not recommended [CODESPLIT] def client_login_authorization_header ( http_method , uri ) if @user && @password && ! @auth_token email = CGI . escape ( @user ) password = CGI . escape ( @password ) http = Net :: HTTP . new ( 'www.google.com' , 443 ) http . use_ssl = true http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE resp , data = http . post ( '/accounts/ClientLogin' , \"accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=wise\" , { 'Content-Type' => 'application/x-www-form-urlencoded' } ) handle_response ( resp ) @auth_token = ( data || resp . body ) [ / /n , 1 ] end @auth_token ? { 'Authorization' => \"GoogleLogin auth=#{@auth_token}\" } : { } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "fulfilled_by? [CODESPLIT] def fulfilled_by? ( contract ) contract . each_clause do | clause | clause . legal_assesment ( @subject ) . tap do | lawyer | unless lawyer . satisfied? @satisfied = false @messages << lawyer . messages end end end @satisfied end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "void write ( string str ) [CODESPLIT] def write_fragment ( str ) if @formatting == :indented # Take the fragment, split up the CRLF's, and write out in an indented manner.\r # Let the formatting of the fragment handle its indentation at our current indent level.\r lines = str . split ( \"\\r\\n\" ) lines . each_with_index do | line , idx | @output << line new_line ( ) if idx < lines . count - 1 # No need for a new line on the last line.\r end else @output << str end nil end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determina se l app è valida . Prende l app corrente se non viene specificata nessuna app . [CODESPLIT] def valid_app? ( app_name = self . current_app ) if app_name . in? self . apps true else raise ExecutionError . new \"The app '#{app_name}' is neither a main app nor an engine \" \"within the project '#{self.name}'.\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ottiene la directory corrente nella cartella dell app specificata . Prende l app corrente se non viene specificata nessuna app . [CODESPLIT] def app_folder ( app_name = self . current_app ) if self . type == :multi if app_name . in? self . main_apps \"#{self.folder}/main_apps/#{app_name}\" elsif app_name . in? self . engines \"#{self.folder}/engines/#{app_name}\" end elsif self . type == :single self . folder end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Determina il file di versione dell app . Prende l app corrente se non viene specificata nessuna app . [CODESPLIT] def app_version_file ( app_name = self . current_app ) Dir . glob ( \"#{app_folder(app_name)}/lib/**/version.rb\" ) . min_by do | filename | filename . chars . count end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Ritorna la versione dell app . Prende l app corrente se non viene specificata nessuna app . [CODESPLIT] def app_version ( app_name = self . current_app ) if File . exists? app_version_file ( app_name ) . to_s File . read ( app_version_file ( app_name ) ) . match ( / \\. \\n / ) . try ( :captures ) . try ( :first ) else ` ` . split ( \"\\n\" ) . first end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Alza la versione dell app corrente a quella specificata . [CODESPLIT] def bump_app_version_to ( version ) if File . exists? self . app_version_file version_file = self . app_version_file version_content = File . read ( \"#{version_file}\" ) File . open ( version_file , 'w+' ) do | f | f . puts version_content . gsub ( / \\. \\n / , \"VERSION = '#{version}'\\n\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inizializza l eseguibile in base al comando passato . [CODESPLIT] def load_project config_file = Dir . glob ( \"#{Dir.pwd}/**/dev.yml\" ) . first raise ExecutionError . new \"No valid configuration files found. Searched for a file named 'dev.yml' \" \"in folder #{Dir.pwd} and all its subdirectories.\" if config_file . nil? @project = Dev :: Project . new ( config_file ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Esegue un comando e cattura l output ritornandolo come risultato di questo metodo . Si può passare l opzione + flush + per stampare subito l output come se non fosse stato catturato . [CODESPLIT] def exec ( command , options = { } ) out , err , status = Open3 . capture3 ( command ) command_output = [ out . presence , err . presence ] . compact . join ( \"\\n\" ) if options [ :flush ] == true puts command_output else command_output end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stampa i comandi possibili . [CODESPLIT] def help puts print \"Dev\" . green print \" - available commands:\\n\" puts print \"\\tversion\\t\\t\" . limegreen print \"Prints current version.\\n\" puts print \"\\tfeature\\t\\t\" . limegreen print \"Opens or closes a feature for the current app.\\n\" print \"\\t\\t\\tWarning: the app is determined from the current working directory!\\n\" print \"\\t\\t\\tExample: \" print \"dev feature open my-new-feature\" . springgreen print \" (opens a new feature for the current app)\" print \".\\n\" print \"\\t\\t\\tExample: \" print \"dev feature close my-new-feature\" . springgreen print \" (closes a developed new feature for the current app)\" print \".\\n\" puts print \"\\thotfix\\t\\t\" . limegreen print \"Opens or closes a hotfix for the current app.\\n\" print \"\\t\\t\\tWarning: the app is determined from the current working directory!\\n\" print \"\\t\\t\\tExample: \" print \"dev hotfix open 0.2.1\" . springgreen print \" (opens a new hotfix for the current app)\" print \".\\n\" print \"\\t\\t\\tExample: \" print \"dev hotfix close 0.2.1\" . springgreen print \" (closes a developed new hotfix for the current app)\" print \".\\n\" puts print \"\\trelease\\t\\t\" . limegreen print \"Opens or closes a release for the current app.\\n\" print \"\\t\\t\\tWarning: the app is determined from the current working directory!\\n\" print \"\\t\\t\\tExample: \" print \"dev release open 0.2.0\" . springgreen print \" (opens a new release for the current app)\" print \".\\n\" print \"\\t\\t\\tExample: \" print \"dev release close 0.2.0\" . springgreen print \" (closes a developed new release for the current app)\" print \".\\n\" puts print \"\\tpull\\t\\t\" . limegreen print \"Pulls specified app's git repository, or pulls all apps if none are specified.\\n\" print \"\\t\\t\\tWarning: the pulled branch is the one the app is currently on!\\n\" print \"\\t\\t\\tExample: \" print \"dev pull [myapp]\" . springgreen print \".\\n\" puts print \"\\tpush\\t\\t\" . limegreen print \"Commits and pushes the specified app.\\n\" print \"\\t\\t\\tWarning: the pushed branch is the one the app is currently on!\\n\" print \"\\t\\t\\tExample: \" print \"dev push myapp \\\"commit message\\\"\" . springgreen print \".\\n\" puts print \"\\ttest\\t\\t\" . limegreen print \"Runs the app's test suite. Tests must be written with rspec.\\n\" print \"\\t\\t\\tIt is possibile to specify which app's test suite to run.\\n\" print \"\\t\\t\\tIf nothing is specified, all main app's test suites are run.\\n\" print \"\\t\\t\\tExample: \" print \"dev test mymainapp myengine\" . springgreen print \" (runs tests for 'mymainapp' and 'myengine')\" print \".\\n\" print \"\\t\\t\\tExample: \" print \"dev test\" . springgreen print \" (runs tests for all main apps and engines within this project)\" print \".\\n\" puts end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET endpoint [CODESPLIT] def get ( endpoint ) uri , http = get_connection ( endpoint ) req = Net :: HTTP :: Get . new ( \"#{uri.path}?#{uri.query}\" ) req . add_field ( \"Content-Type\" , \"application/json\" ) req . add_field ( \"User-Agent\" , \"Sigimera Ruby Client v#{Sigimera::VERSION}\" ) http . request ( req ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST endpoint [CODESPLIT] def post ( endpoint , basic_hash = nil ) uri , http = get_connection ( endpoint ) req = Net :: HTTP :: Post . new ( \"#{uri.path}?#{uri.query}\" ) req . add_field ( \"Content-Type\" , \"application/json\" ) req . add_field ( \"User-Agent\" , \"Sigimera Ruby Client v#{Sigimera::VERSION}\" ) req . add_field ( \"Authorization\" , \"Basic #{basic_hash}\" ) if basic_hash http . request ( req ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "HEAD endpoint [CODESPLIT] def head ( endpoint ) uri , http = get_connection ( endpoint ) req = Net :: HTTP :: Head . new ( \"#{uri.path}?#{uri.query}\" ) req . add_field ( \"User-Agent\" , \"Sigimera Ruby Client v#{Sigimera::VERSION}\" ) http . request ( req ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve Lumberjack :: LogEntry objects from the MongoDB collection . If a block is given it will be yielded to with each entry . Otherwise it will return an array of all the entries . [CODESPLIT] def find ( selector , options = { } , & block ) entries = [ ] @collection . find ( selector , options ) do | cursor | cursor . each do | doc | entry = LogEntry . new ( doc [ TIME ] , doc [ SEVERITY ] , doc [ MESSAGE ] , doc [ PROGNAME ] , doc [ PID ] , doc [ UNIT_OF_WORK_ID ] ) if block_given? yield entry else entries << entry end end end block_given? ? nil : entries end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Helper method . Updates the search words with the text returned by search_strings . [CODESPLIT] def update_pose_words self . pose_words . delete ( Word . factory ( pose_stale_words true ) ) self . pose_words << Word . factory ( pose_words_to_add ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new TimedHashMarking Creates token with + object + as its value and adds it to the marking . if no timestamp is given current time will be used . [CODESPLIT] def add ( objects , timestamp = @time ) unless objects . kind_of? Array objects = [ objects ] end objects . each do | object | if object . instance_of? Hash timestamp = object [ :ts ] || 0 object = object [ :val ] end token = prepare_token ( object , timestamp ) timestamp = token . timestamp if timestamp > @time add_to_waiting token else add_token token end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set current time for the marking . This will cause moving tokens from waiting to active list . Putting clock back will cause error . [CODESPLIT] def time = ( time ) if time < @time raise InvalidTime . new ( \"You are trying to put back clock from #{@time} back to #{time}\" ) end @time = time @waiting . keys . sort . each do | timestamp | if timestamp > @time @next_time = timestamp break end @waiting [ timestamp ] . each { | token | add_token token } @waiting . delete timestamp end @next_time = 0 if @waiting . empty? @time end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Send a message to the remote host [CODESPLIT] def send_message data , binary = false if established? unless @closing @socket . send_data ( @encoder . encode ( data . to_s , binary ? BINARY_FRAME : TEXT_FRAME ) ) end else raise WebSocketError . new \"can't send on a closed channel\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : setup encoder / decoder and bind to all decoder events . [CODESPLIT] def on_handshake_complete @decoder . onping do | data | @socket . send_data @encoder . pong ( data ) emit :ping , data end @decoder . onpong do | data | emit :pong , data end @decoder . onclose do | code | close code end @decoder . onframe do | frame , binary | emit :frame , frame , binary end @decoder . onerror do | code , message | close code , message emit :error , code , message end emit :open if @handshake . extra receive_message_data @handshake . extra end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Internal : Connect to the remote host and synchonize the socket and this client object [CODESPLIT] def connect EM . connect @uri . host , @uri . port || 80 , WebSocketConnection do | conn | conn . client = self conn . send_data ( @handshake . request ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def short_key key = @@key return \"\" if key . nil? || key . empty? key [ 0 .. 3 ] + \"...\" + key [ ( key . length - 4 ) .. ( key . length - 1 ) ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "== instance methods Make a POST API call with the current path value and [CODESPLIT] def post ( options ) uri = new_uri params = merge_params ( options ) response = Net :: HTTP . post_form ( uri , params ) unless response . is_a? ( Net :: HTTPSuccess ) raise \"#{response.code} #{response.message}\\n#{response.body}\" end response . body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make a DELETE API call with the current path value and [CODESPLIT] def delete ( options = { } ) uri = new_uri params = merge_params ( options ) uri . query = URI . encode_www_form ( params ) http = Net :: HTTP . new ( uri . host , uri . port ) request = Net :: HTTP :: Delete . new ( uri ) # uri or uri.request_uri? response = http . request ( request ) unless response . is_a? ( Net :: HTTPSuccess ) raise \"#{response.code} #{response.message}\\n#{response.body}\" end true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def short_token return \"\" if access_token . nil? || access_token . empty? access_token [ 0 .. 3 ] + \"...\" + access_token [ ( access_token . length - 4 ) .. ( access_token . length - 1 ) ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a has representing the named instance . This is suitable for Puppet type and provider or you can use the returned info for whatever you like [CODESPLIT] def instance_metadata ( name ) instance = instance ( name ) config = { } # annotate the raw config hash with data for puppet (and humans...) if instance . configured? config = instance . configfile_hash config [ \"ensure\" ] = :present else # VM missing or damaged config [ \"ensure\" ] = :absent end config [ \"name\" ] = name config end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return a hash of all instances [CODESPLIT] def instances_metadata ( ) instance_wildcard = File . join ( @vagrant_vm_dir , \"*\" , :: Vagrantomatic :: Instance :: VAGRANTFILE ) instances = { } Dir . glob ( instance_wildcard ) . each { | f | elements = f . split ( File :: SEPARATOR ) # /var/lib/vagrantomatic/mycoolvm/Vagrantfile # -----------------------^^^^^^^^------------ name = elements [ elements . size - 2 ] instances [ name ] = instance_metadata ( name ) } instances end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read a csv from + path + . Returns an array of Structs using the keys from the csv header row . [CODESPLIT] def csv_read ( path ) lines = begin if path =~ / \\. / Zlib :: GzipReader . open ( path ) do | f | CSV . new ( f ) . read end else CSV . read ( path ) end end keys = lines . shift . map ( :to_sym ) klass = Struct . new ( keys ) lines . map { | i | klass . new ( i ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write + rows + to + path + as csv . Rows can be an array of hashes Structs OpenStructs or anything else that responds to to_h . The keys from the first row are used as the csv header . If + cols + is specified it will be used as the column keys instead . [CODESPLIT] def csv_write ( path , rows , cols : nil ) atomic_write ( path ) do | tmp | CSV . open ( tmp . path , \"wb\" ) { | f | csv_write0 ( f , rows , cols : cols ) } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write + rows + to $stdout as a csv . Similar to csv_write . [CODESPLIT] def csv_to_stdout ( rows , cols : nil ) CSV ( $stdout ) { | f | csv_write0 ( f , rows , cols : cols ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a string containing + rows + as a csv . Similar to csv_write . [CODESPLIT] def csv_to_s ( rows , cols : nil ) string = \"\" f = CSV . new ( StringIO . new ( string ) ) csv_write0 ( f , rows , cols : cols ) string end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def csv_write0 ( csv , rows , cols : nil ) # cols cols ||= rows . first . to_h . keys csv << cols # rows rows . each do | row | row = row . to_h csv << cols . map { | i | row [ i ] } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add Value is how we add keys to the resulting Struct We need a name and a type and potentially a subtype [CODESPLIT] def add_value ( name , type , subtype = nil ) if type . class == RustyJson :: RustStruct || subtype . class == RustyJson :: RustStruct if type . class == RustyJson :: RustStruct t = type type = type . name struct = t elsif subtype . class == RustyJson :: RustStruct s = subtype subtype = subtype . name struct = s end @structs << struct RustStruct . add_type ( struct . name , struct . name ) end @values [ name ] = [ type , subtype ] true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "two Rust structs are equal if all of their keys / value types are the same to_s controlls how to display the RustStruct as a Rust Struct [CODESPLIT] def to_s return '' if @printed @printed = true struct = required_structs members = @values . map do | key , value | type = RustStruct . type_name ( value [ 0 ] ) subtype = RustStruct . type_name ( value [ 1 ] ) # TODO: add option for pub / private #       Will this be a per field thing that is configurable from #       within the JSON or will it be configured on the parse command? member = \"    pub #{key}: #{type}\" member << \"<#{subtype}>\" unless value [ 1 ] . nil? member end struct << \"pub struct #{@name} {\\n\" + members . join ( \",\\n\" ) + \",\\n}\\n\\n\" struct = struct . gsub ( \"\\n\\n\\n\" , \"\\n\\n\" ) reset if @root struct end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Thor Helpers [CODESPLIT] def option_copy_file from_path , to_path , file_type , template = false if File . exist? ( to_path ) if options [ :overwrite ] remove_file ( to_path ) if template template from_path , to_path else copy_file from_path , to_path end else puts \"ERROR: Failed to #{template ? \"template\" : \"copy\"} #{file_type || 'file'}. #{to_path} exists. Delete file or use the --overwrite=true option when generating the layout\" end else if template template from_path , to_path else copy_file from_path , to_path end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "CRUD [CODESPLIT] def create ( name ) return false unless @widgets . where ( name ) . empty? time_now = now @widgets . add ( :name => name , :created_at => time_now , :modified_at => time_now ) save_widgets true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A callback that runs before create vote Example : BallotBox :: Manager . before_vote do |env opts| end [CODESPLIT] def before_vote ( options = { } , method = :push , & block ) raise BlockNotGiven unless block_given? _before_vote . send ( method , [ block , options ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A callback that runs after vote created Example : BallotBox :: Manager . after_vote do |env opts| end [CODESPLIT] def after_vote ( options = { } , method = :push , & block ) raise BlockNotGiven unless block_given? _after_vote . send ( method , [ block , options ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "content [CODESPLIT] def content ( lang = '' ) filename = content_filename_full ( lang ) return nil if filename . nil? return '' if ! File . exists? filename File . read ( filename ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "search = begin def self . search_by_filter ( filter ) pg = filter . page #pg = 1 if pg . nil? || pg< = 0 [CODESPLIT] def _before_save if self . url_changed? self . url_parts_count = PageServices :: PageRouteService . count_url_parts ( self . url ) self . url_vars_count = PageServices :: PageRouteService :: count_url_vars ( self . url ) self . parsed_url = PageServices :: PageRouteService :: parse_url ( self . url ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def bibliographical_book ( options = {} ) bibliographical_book_extractor = Biblionet :: Extractors :: BibliographicalBookExtractor . new uri = http : // www . biblionet . gr / main . asp?page = results&Titlesid = # { options [ : id ] } options [ : format ] || = [CODESPLIT] def category ( options = { } ) uri = process_options ( options , __method__ ) options [ :format ] ||= @format category_extractor = Biblionet :: Extractors :: CategoryExtractor . new category = category_extractor . extract_categories_from ( uri ) response = { } response [ :category ] = ! category . nil? ? [ category ] : [ ] response = change_format ( response , options [ :format ] ) return response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Rotate servers given [CODESPLIT] def rotate ( hsh ) current_ec2 , new_ec2 = hsh . first cur_instances = EC2 . by_tags ( \"Name\" => current_ec2 . to_s ) new_instances = EC2 . by_tags ( \"Name\" => new_ec2 . to_s ) register_and_wait new_instances deregister cur_instances end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wait for all the instances to become InService [CODESPLIT] def wait_for_state ( instances , exp_state ) time = 0 all_good = false loop do all_good = instances . all? do | i | state = i . elb_health [ :state ] puts \"#{i.id}: #{state}\" exp_state == state end break if all_good || time > timeout sleep 1 time += 1 end # If timeout before all inservice, deregister and raise error unless all_good raise \"Instances are out of service\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read a value from an OW path . [CODESPLIT] def read ( path ) owconnect do | socket | owwrite ( socket , :path => path , :function => READ ) return to_number ( owread ( socket ) . data ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write a value to an OW path . [CODESPLIT] def write ( path , value ) owconnect do | socket | owwrite ( socket , :path => path , :value => value . to_s , :function => WRITE ) return owread ( socket ) . return_value end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List the contents of an OW path . [CODESPLIT] def dir ( path ) owconnect do | socket | owwrite ( socket , :path => path , :function => DIR ) fields = [ ] while true response = owread ( socket ) if response . data fields << response . data else break end end return fields end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "sums up statistics across all queries indexed by model [CODESPLIT] def sum_totals_by_model @sum_totals_by_model ||= begin totals = Hash . new { | hash , key | hash [ key ] = Hash . new ( 0 ) } @queries_by_model . each do | model , queries | totals [ model ] [ :query_count ] = queries . length queries . each do | query | query . statistics . each do | stat , value | totals [ model ] [ stat ] += value end end totals [ model ] [ :datastore_interaction_time ] = totals [ model ] [ :datastore_interaction_time ] end totals end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "sums up statistics across all models and queries [CODESPLIT] def sum_totals @sum_totals ||= begin totals = Hash . new ( 0 ) sum_totals_by_model . each do | _ , model_totals | model_totals . each do | stat , value | totals [ stat ] += value end end totals end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "NOTE : May be causing memory bloat [CODESPLIT] def subscribed_to? ( stripe_id ) subscription_plan = self . subscription . plan if self . subscription . present? if subscription_plan . present? return true if subscription_plan . stripe_id == stripe_id if Tang . plan_inheritance other_plan = Plan . find_by ( stripe_id : stripe_id ) return true if other_plan . present? && subscription_plan . order >= other_plan . order end end return false end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "[ OVERRIDE ] write_attribute to account for setting hash_key and id to same value u . id = 1 * set id to 1 * set hash_key to 1 u . hash_key = 2 * set hash_key to 2 * set id to 2 [CODESPLIT] def write_attribute ( key , value ) key = key . to_s attribute = attribute_instance ( key ) if self . class . dynamo_table . hash_key [ :attribute_name ] != \"id\" # If primary hash_key is not the standard `id` if key == self . class . dynamo_table . hash_key [ :attribute_name ] @attributes [ key ] = attribute_instance ( key ) . from_store ( value ) return @attributes [ \"id\" ] = attribute_instance ( \"id\" ) . from_store ( value ) elsif key == \"id\" @attributes [ \"id\" ] = attribute_instance ( \"id\" ) . from_store ( value ) return @attributes [ self . class . dynamo_table . hash_key [ :attribute_name ] ] = attribute_instance ( self . class . dynamo_table . hash_key [ :attribute_name ] ) . from_store ( value ) end end @attributes [ key ] = attribute . from_store ( value ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "source : https : // github . com / arnau / ISO8601 / blob / master / lib / iso8601 / duration . rb ( MIT ) [CODESPLIT] def iso8601 duration = @seconds sign = '-' if ( duration < 0 ) duration = duration . abs years , y_mod = ( duration / YEARS_FACTOR ) . to_i , ( duration % YEARS_FACTOR ) months , m_mod = ( y_mod / MONTHS_FACTOR ) . to_i , ( y_mod % MONTHS_FACTOR ) days , d_mod = ( m_mod / 86400 ) . to_i , ( m_mod % 86400 ) hours , h_mod = ( d_mod / 3600 ) . to_i , ( d_mod % 3600 ) minutes , mi_mod = ( h_mod / 60 ) . to_i , ( h_mod % 60 ) seconds = mi_mod . div ( 1 ) == mi_mod ? mi_mod . to_i : mi_mod . to_f # Coerce to Integer when needed (`PT1S` instead of `PT1.0S`) seconds = ( seconds != 0 or ( years == 0 and months == 0 and days == 0 and hours == 0 and minutes == 0 ) ) ? \"#{seconds}S\" : \"\" minutes = ( minutes != 0 ) ? \"#{minutes}M\" : \"\" hours = ( hours != 0 ) ? \"#{hours}H\" : \"\" days = ( days != 0 ) ? \"#{days}D\" : \"\" months = ( months != 0 ) ? \"#{months}M\" : \"\" years = ( years != 0 ) ? \"#{years}Y\" : \"\" date = %[#{sign}P#{years}#{months}#{days}] time = ( hours != \"\" or minutes != \"\" or seconds != \"\" ) ? %[T#{hours}#{minutes}#{seconds}] : \"\" date + time end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Warning this will probably gain inappropriate accuracy - Ruby does not support the same level of timing accuracy as TAI64N and TA64NA can provide . [CODESPLIT] def to_label s = '%016x%08x' sec = tai_second ts = if sec >= 0 sec + EPOCH else EPOCH - sec end Label . new s % [ ts , tai_nanosecond ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Inject a named object into this context [CODESPLIT] def put ( name , object ) raise \"This ObjectContext already has an instance or configuration for '#{name.to_s}'\" if directly_has? ( name ) Conject . install_object_context ( object , self ) object . instance_variable_set ( :@_conject_contextual_name , name . to_s ) @cache [ name . to_sym ] = object end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a named object from this context . If the object is already existant in this context return it . If we have a parent context and it contains the requested object get and return object from parent context . ( Recursive upward search ) If the object exists nowhere in this or a super context : construct cache and return a new instance of the requested object using the object factory . [CODESPLIT] def get ( name ) name = name . to_sym return @cache [ name ] if @cache . keys . include? ( name ) if ! has_config? ( name ) and parent_context and parent_context . has? ( name ) return parent_context . get ( name ) else object = object_factory . construct_new ( name , self ) object . instance_variable_set ( :@_conject_contextual_name , name . to_s ) @cache [ name ] = object unless no_cache? ( name ) return object end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allow configuration options to be set for named objects . [CODESPLIT] def configure_objects ( confs = { } ) confs . each do | key , opts | key = key . to_sym @object_configs [ key ] = { } unless has_config? ( key ) @object_configs [ key ] . merge! ( opts ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "override aruba [CODESPLIT] def run_simple ( cmd , fail_on_error = true ) # run development version in verbose mode cmd = cmd . gsub ( / / , \"ruby -S #{APP_BIN_PATH} --verbose\" ) # run original aruba 'run' old_run_simple ( cmd , fail_on_error ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "call api [CODESPLIT] def talk ( msg ) response = @http . start do | h | res = h . request ( request ( msg ) ) JSON . parse ( res . body ) end if err = response [ 'requestError' ] raise err . inspect end @context = response [ 'context' ] response [ 'utt' ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs httperf with a given request rate . Parses the output and returns a hash with the results . [CODESPLIT] def httperf warm_up = false httperf_cmd = build_httperf_cmd if warm_up # Do a warm up run to setup any resources status \"\\n#{httperf_cmd} (warm up run)\" IO . popen ( \"#{httperf_cmd} 2>&1\" ) else IO . popen ( \"#{httperf_cmd} 2>&1\" ) do | pipe | status \"\\n#{httperf_cmd}\" @results << ( httperf_result = HttperfResult . new ( { :rate => @current_rate , :server => @current_job . server , :port => @current_job . port , :uri => @current_job . uri , :num_conns => @current_job . num_conns , :description => @current_job . description } ) ) HttperfResultParser . new ( pipe ) . parse ( httperf_result ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Converts a path and params to a Salesforce - suitable URL . [CODESPLIT] def url ( path , params = { } ) params = params . inject ( { } , @@stringify ) path = path . gsub ( @@placeholder ) { params . delete ( $1 , @@required ) } params = params . inject ( '' , @@parameterize ) [ path , params ] . reject ( :nil? ) . reject ( :empty? ) . join ( '?' ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "endpoint takes a map and for eack key / value pair adds a singleton method to the map which will fetch that resource ( if it looks like a URL ) . [CODESPLIT] def endpoint ( map ) map . each { | k , v | apply_endpoint ( map , k , v ) } map end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "applies an endpoint to obj named k which fetches v and makes it an endpoint if it looks like a URL [CODESPLIT] def apply_endpoint ( obj , k , v ) α    >    ndpoint( g et( v ) . b ody)    β    >       λ    rl?( v )     >    .c a ll } : -  { β ca l l }  obj . define_singleton_method ( k , λ)   f  rl?( v )  obj end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Identifies a valid URL for this REST instance [CODESPLIT] def url? ( string ) return false unless string . to_s =~ url_pattern return false if string . to_s =~ @@placeholder true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assert if two objects are equal [CODESPLIT] def assit_equal ( expected , actual , message = \"Object expected to be equal\" ) if ( expected != actual ) message << \" expected #{expected} but was #{actual}\" assit ( false , message ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Assert if something is of the right type [CODESPLIT] def assit_kind_of ( klass , object , message = \"Object of wrong type\" ) if ( ! object . kind_of? ( klass ) ) message << \" (Expected #{klass} but was #{object.class})\" assit ( false , message ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Duck typing assertion : This checks if the given object responds to the given method calls . This won t detect any calls that will be handled through method_missing of course . [CODESPLIT] def assit_quack ( object , methods , message = \"Quack assert failed.\" ) unless ( methods . kind_of? ( Enumerable ) ) methods = [ methods ] end methods . each do | method | unless ( object . respond_to? ( method . to_sym ) ) assit ( false , \"#{message} - Method: #{method.to_s}\" ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Asserts that the given element is a string that is not nil and not an empty string or a string only containing whitspaces [CODESPLIT] def assit_real_string ( object , message = \"Not a non-empty string.\" ) unless ( object && object . kind_of? ( String ) && object . strip != \"\" ) assit ( false , message ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Executes the given block and asserts if the result is true . This allows you to assert on complex custom expressions and be able to disable those expressions together with the assertions . See the README for more . [CODESPLIT] def assit_block ( & block ) errors = [ ] assit ( ( block . call ( errors ) && errors . size == 0 ) , errors . join ( ', ' ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "I m passing in a time variable here to make links unique . You see if you parse many of these entries on a single HTML page you ll end up with multiple #footnote1 divs . To make them unique we ll pass down a time variable from above to seed them . [CODESPLIT] def html ( footnote_seed , time ) paragraph_content = sequence . elements . map do | element | if element . respond_to? ( :footnote_html ) footnote_seed += 1 element . html ( footnote_seed , time ) elsif element . respond_to? ( :newline ) element . newline . html else element . html end end . join Build . tag ( \"p\" , paragraph_content ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "I m passing in a time variable here to make links unique . You see if you parse many of these entries on a single HTML page you ll end up with multiple #footnote1 divs . To make them unique we ll pass down a time variable from above to seed them . [CODESPLIT] def footnote_html ( footnote_seed , time ) footnote_content = sequence . elements . reduce ( [ ] ) do | memo , element | if element . respond_to? ( :footnote_html ) footnote_seed += 1 memo + [ element . footnote_html ( footnote_seed , time ) ] else memo end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "POST / uploads [CODESPLIT] def create @upload = Upload . new ( upload_params ) #{\"fileName\":\"image(13).png\",\"uploaded\":1,\"url\":\"\\/ckfinder\\/userfiles\\/files\\/image(13).png\",\"error\":{\"number\":201,\"message\":\"A file with the same name is already available. The uploaded file was renamed to \\\"image(13).png\\\".\"}} @upload . save respond_to do | format | format . json { render plain : { fileName : @upload . file . filename , uploaded : 1 , url : @upload . file . url } . to_json } end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "constructor [CODESPLIT] def authenticate options = { body : \"username=#{@user}&password=#{@pass}\" } # Have to clear out the cookies or the old SID gets sent while requesting # the new SID (and it fails). self . class . cookies . clear res = self . class . post ( '/login' , options ) if res . success? token = res . headers [ \"Set-Cookie\" ] raise QbtClientError . new ( \"Login failed: no SID (cookie) returned\" ) if token . nil? token = token . split ( \";\" ) [ 0 ] @sid = token else raise QbtClientError . new ( res ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Polls the client for incremental changes . [CODESPLIT] def poll interval : 10 , & block raise '#poll requires a block' unless block_given? response_id = 0 loop do res = self . sync response_id if res response_id = res [ 'rid' ] yield res end sleep interval end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Requests partial data from the client . [CODESPLIT] def sync response_id = 0 req = self . class . get '/sync/maindata' , format : :json , query : { rid : response_id } res = req . parsed_response if req . success? return res end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add one or more trackers to a torrent [CODESPLIT] def add_trackers torrent_hash , urls urls = Array ( urls ) # Ampersands in urls must be escaped. urls = urls . map { | url | url . gsub ( '&' , '%26' ) } urls = urls . join ( '%0A' ) options = { body : \"hash=#{torrent_hash}&urls=#{urls}\" } self . class . post ( '/command/addTrackers' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Begin downloading one or more torrents . [CODESPLIT] def download urls urls = Array ( urls ) urls = urls . join ( '%0A' ) options = { body : \"urls=#{urls}\" } self . class . post ( '/command/download' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete one or more torrents AND THEIR DATA [CODESPLIT] def delete_torrent_and_data torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/deletePerm' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete one or more torrents ( doesn t delete their data ) [CODESPLIT] def delete torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/delete' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set location for a torrent [CODESPLIT] def set_location ( torrent_hashes , path ) torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : { \"hashes\" => torrent_hashes , \"location\" => path } , } self . class . post ( '/command/setLocation' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Increase the priority of one or more torrents [CODESPLIT] def increase_priority torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/increasePrio' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decrease the priority of one or more torrents [CODESPLIT] def decrease_priority torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/decreasePrio' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Increase the priority of one or more torrents to the maximum value [CODESPLIT] def maximize_priority torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/topPrio' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decrease the priority of one or more torrents to the minimum value [CODESPLIT] def minimize_priority torrent_hashes torrent_hashes = Array ( torrent_hashes ) torrent_hashes = torrent_hashes . join ( '|' ) options = { body : \"hashes=#{torrent_hashes}\" } self . class . post ( '/command/bottomPrio' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set the download priority of a file within a torrent [CODESPLIT] def set_file_priority torrent_hash , file_id , priority query = [ \"hash=#{torrent_hash}\" , \"id=#{file_id}\" , \"priority=#{priority}\" ] options = { body : query . join ( '&' ) } self . class . post ( '/command/setFilePrio' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set a torrent s download limit [CODESPLIT] def set_download_limit torrent_hash , limit query = [ \"hashes=#{torrent_hash}\" , \"limit=#{limit}\" ] options = { body : query . join ( '&' ) } self . class . post ( '/command/setTorrentsDlLimit' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Set a torrent s upload limit [CODESPLIT] def set_upload_limit torrent_hash , limit query = [ \"hashes=#{torrent_hash}\" , \"limit=#{limit}\" ] options = { body : query . join ( '&' ) } self . class . post ( '/command/setTorrentsUpLimit' , options ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Return the md5 checksum for the file at + path + . [CODESPLIT] def md5_file ( path ) File . open ( path ) do | f | digest , buf = Digest :: MD5 . new , \"\" while f . read ( 4096 , buf ) digest . update ( buf ) end digest . hexdigest end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterate over all keys . [CODESPLIT] def keys ( * a ) if block_given? bucket . keys ( a ) do | keys | # This API is currently inconsistent from protobuffs to http if keys . kind_of? Array keys . each do | key | yield key end else yield keys end end else bucket . keys ( a ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Iterate over all items using key streaming . [CODESPLIT] def each bucket . keys do | keys | keys . each do | key | if x = self [ key ] yield x end end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run an external command . Raise Error if something goes wrong . The command will be echoed if verbose? . [CODESPLIT] def run ( command , args = nil ) cmd = CommandLine . new ( command , args ) vputs ( cmd ) cmd . run end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a list of clicks based on the following parameters [CODESPLIT] def clicks ( options = { } ) options = update_by_expire_time options if clicks_not_latest? ( options ) @rsqoot_clicks = get ( 'clicks' , options , SqootClick ) @rsqoot_clicks = @rsqoot_clicks . clicks if @rsqoot_clicks @rsqoot_clicks = @rsqoot_clicks . clicks . map ( :click ) if @rsqoot_clicks . clicks end logger ( uri : sqoot_query_uri , records : @rsqoot_clicks , type : 'clicks' , opts : options ) @rsqoot_clicks end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build instances using build options [CODESPLIT] def build_instances ( template = nil ) build_args = if template == :template [ build_options . first . merge ( count : 1 ) ] else build_options end build_args . map do | args | instances = create_instance args apply_tags ( instances ) instances end . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initialize a new ScopeCreator object [CODESPLIT] def scope ( scope_name , scope_enum_keys ) target_enum = @record_class . defined_enums [ @enum_name . to_s ] sub_enum_values = target_enum . values_at ( scope_enum_keys ) if @record_class . defined_enum_scopes . has_key? ( scope_name ) fail ArgumentError , \"Conflicting scope names. A scope named #{scope_name} has already been defined\" elsif sub_enum_values . include? ( nil ) unknown_key = scope_enum_keys [ sub_enum_values . index ( nil ) ] fail ArgumentError , \"Unknown key - #{unknown_key} for enum #{@enum_name}\" elsif @record_class . respond_to? ( scope_name . to_s . pluralize ) fail ArgumentError , \"Scope name - #{scope_name} conflicts with a class method of the same name\" elsif @record_class . instance_methods . include? ( \"#{scope_name}?\" . to_sym ) fail ArgumentError , \"Scope name - #{scope_name} conflicts with the instance method - #{scope_name}?\" end sub_enum_entries = target_enum . slice ( scope_enum_keys ) @record_class . defined_enum_scopes [ scope_name ] = sub_enum_entries # 1. Instance method <scope_name>? @record_class . send ( :define_method , \"#{scope_name}?\" ) { sub_enum_entries . include? self . role } # 2. The class scope with the scope name @record_class . scope scope_name . to_s . pluralize , -> { @record_class . where ( \"#{@enum_name}\" => sub_enum_entries . values ) } @scope_names << scope_name end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Public : Feed the decoder raw data from the wire [CODESPLIT] def << data # put the data into the buffer, as # we might be replaying if data @buffer << data end # Don't do work if we don't have to if @buffer . length < 2 return end # decode the first 2 bytes, with # opcode, lengthgth, masking bit, and frag bit h1 , h2 = @buffer . unpack ( \"CC\" ) # check the fragmentation bit to see # if this is a message fragment fin = ( ( h1 & 0x80 ) == 0x80 ) # used to keep track of our position in the buffer offset = 2 # see above for possible opcodes opcode = ( h1 & 0x0F ) # the leading length idicator length = ( h2 & 0x7F ) # masking bit, is the data masked with # a specified masking key? masked = ( ( h2 & 0x80 ) == 0x80 ) # Find errors and fail fast if h1 & 0b01110000 != 0 return emit :error , 1002 , \"RSV bits must be 0\" end if opcode > 7 if ! fin return emit :error , 1002 , \"Control frame cannot be fragmented\" elsif length > 125 return emit :error , 1002 , \"Control frame is too large #{length}\" elsif opcode > 0xA return emit :error , 1002 , \"Unexpected reserved opcode #{opcode}\" elsif opcode == CLOSE && length == 1 return emit :error , 1002 , \"Close control frame with payload of length 1\" end else if opcode != CONTINUATION && opcode != TEXT_FRAME && opcode != BINARY_FRAME return emit :error , 1002 , \"Unexpected reserved opcode #{opcode}\" end end # Get the actual size of the payload if length > 125 if length == 126 length = @buffer . unpack ( \"@#{offset}n\" ) . first offset += 2 else length = @buffer . unpack ( \"@#{offset}L!>\" ) . first offset += 8 end end # unpack the masking key if masked key = @buffer . unpack ( \"@#{offset}N\" ) . first offset += 4 end # replay on next frame if @buffer . size < ( length + offset ) return false end # Read the important bits payload = @buffer . unpack ( \"@#{offset}C#{length}\" ) # Unmask the data if it\"s masked if masked payload . bytesize . times do | i | payload [ i ] = ( ( payload [ i ] ^ ( key >> ( ( 3 - ( i % 4 ) ) * 8 ) ) ) & 0xFF ) end end payload = payload . pack ( \"C*\" ) case opcode when CONTINUATION # We shouldn't get a contination without # knowing whether or not it's binary or text unless @fragmented return emit :error , 1002 , \"Unexepected continuation\" end if @fragmented == :text @chunks << payload . force_encoding ( \"UTF-8\" ) else @chunks << payload end if fin if @fragmented == :text && ! valid_utf8? ( @chunks ) return emit :error , 1007 , \"Invalid UTF\" end emit :frame , @chunks , @fragmented == :binary @chunks = nil @fragmented = false end when TEXT_FRAME # We shouldn't get a text frame when we # are expecting a continuation if @fragmented return emit :error , 1002 , \"Unexepected frame\" end # emit or buffer if fin unless valid_utf8? ( payload ) return emit :error , 1007 , \"Invalid UTF Hmm\" end emit :frame , payload , false else @chunks = payload . force_encoding ( \"UTF-8\" ) @fragmented = :text end when BINARY_FRAME # We shouldn't get a text frame when we # are expecting a continuation if @fragmented return emit :error , 1002 , \"Unexepected frame\" end # emit or buffer if fin emit :frame , payload , true else @chunks = payload @fragmented = :binary end when CLOSE code , explain = payload . unpack ( \"nA*\" ) if explain && ! valid_utf8? ( explain ) emit :close , 1007 else emit :close , response_close_code ( code ) end when PING emit :ping , payload when PONG emit :pong , payload end # Remove data we made use of and call back # TODO: remove recursion @buffer = @buffer [ offset + length .. - 1 ] || \"\" if not @buffer . empty? self << nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "read options from YAML config [CODESPLIT] def configure # config file default options configuration = { :options => { :verbose => false , :coloring => 'AUTO' } , :mount => { :source => { :name => nil } , :mountpoint => { :name => nil } , :passphrasefile => { :name => 'passphrase' } , :keyfile => { :name => 'encfs6.xml' } , :cmd => nil , :executable => nil } , :unmount => { :mountpoint => { :name => nil } , :cmd => nil , :executable => nil } , :copy => { :source => { :name => nil } , :destination => { :name => nil } , :cmd => nil , :executable => nil } } # set default config if not given on command line config = @options [ :config ] unless config config = [ File . join ( @working_dir , \"revenc.conf\" ) , File . join ( @working_dir , \".revenc.conf\" ) , File . join ( @working_dir , \"config\" , \"revenc.conf\" ) , File . expand_path ( File . join ( \"~\" , \".revenc.conf\" ) ) ] . detect { | filename | File . exists? ( filename ) } end if config && File . exists? ( config ) # rewrite options full path for config for later use @options [ :config ] = config # load options from the config file, overwriting hard-coded defaults config_contents = YAML :: load ( File . open ( config ) ) configuration . merge! ( config_contents . symbolize_keys! ) if config_contents && config_contents . is_a? ( Hash ) else # user specified a config file?, no error if user did not specify config file raise \"config file not found\" if @options [ :config ] end # the command line options override options read from the config file @options = configuration [ :options ] . merge! ( @options ) @options . symbolize_keys! # mount, unmount and copy configuration hashes @options [ :mount ] = configuration [ :mount ] . recursively_symbolize_keys! if configuration [ :mount ] @options [ :unmount ] = configuration [ :unmount ] . recursively_symbolize_keys! if configuration [ :unmount ] @options [ :copy ] = configuration [ :copy ] . recursively_symbolize_keys! if configuration [ :copy ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "PATCH / PUT / subscriptions / 1 [CODESPLIT] def update @subscription . end_trial_now = ( params [ :subscription ] [ :end_trial_now ] == '1' ) if @subscription . end_trial_now params [ :subscription ] [ 'trial_end(1i)' ] = '' params [ :subscription ] [ 'trial_end(2i)' ] = '' params [ :subscription ] [ 'trial_end(3i)' ] = '' end if @subscription . update ( subscription_params ) redirect_to [ :admin , @subscription ] , notice : 'Subscription was successfully updated.' else render :edit end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Initializes a new feedtosis library . It must be initialized with a valid URL as the first argument . A following optional + options + Hash may take the arguments : * backend : a key - value store to be used for summary structures of feeds fetched . Moneta backends work well but any object acting like a Hash is valid . * retained_digest_size : an Integer specifying the number of previous MD5 sets of entries to keep used for new feed detection Retrieves the latest entries from this feed . Returns a Feedtosis :: Result object which delegates methods to the Curl :: Easy object making the request and the FeedNormalizer :: Feed object that may have been created from the HTTP response body . [CODESPLIT] def fetch curl = build_curl_easy curl . perform feed = process_curl_response ( curl ) Feedtosis :: Result . new ( curl , feed ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Marks entries as either seen or not seen based on the unique signature of the entry which is calculated by taking the MD5 of common attributes . [CODESPLIT] def mark_new_entries ( response ) digests = summary_digests # For each entry in the responses object, mark @_seen as false if the  # digest of this entry doesn't exist in the cached object. response . entries . each do | e | seen = digests . include? ( digest_for ( e ) ) e . instance_variable_set ( :@_seen , seen ) end response end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Processes the results by identifying which entries are new if the response is a 200 . Otherwise returns the Curl :: Easy object for the user to inspect . [CODESPLIT] def process_curl_response ( curl ) if curl . response_code == 200 response = parser_for_xml ( curl . body_str ) response = mark_new_entries ( response ) store_summary_to_backend ( response , curl ) response end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Sets the headers from the backend if available [CODESPLIT] def set_header_options ( curl ) summary = summary_for_feed unless summary . nil? curl . headers [ 'If-None-Match' ] = summary [ :etag ] unless summary [ :etag ] . nil? curl . headers [ 'If-Modified-Since' ] = summary [ :last_modified ] unless summary [ :last_modified ] . nil? end curl end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Stores information about the retrieval including ETag Last - Modified and MD5 digests of all entries to the backend store . This enables conditional GET usage on subsequent requests and marking of entries as either new or seen . [CODESPLIT] def store_summary_to_backend ( feed , curl ) headers = HttpHeaders . new ( curl . header_str ) # Store info about HTTP retrieval summary = { } summary . merge! ( :etag => headers . etag ) unless headers . etag . nil? summary . merge! ( :last_modified => headers . last_modified ) unless headers . last_modified . nil? # Store digest for each feed entry so we can detect new feeds on the next  # retrieval new_digest_set = feed . entries . map do | e | digest_for ( e ) end new_digest_set = summary_for_feed [ :digests ] . unshift ( new_digest_set ) new_digest_set = new_digest_set [ 0 .. @options [ :retained_digest_size ] ] summary . merge! ( :digests => new_digest_set ) set_summary ( summary ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes a unique signature for the FeedNormalizer :: Entry object given . This signature will be the MD5 of enough fields to have a reasonable probability of determining if the entry is unique or not . [CODESPLIT] def digest_for ( entry ) MD5 . hexdigest ( [ entry . title , entry . content , entry . date_published ] . join ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Print a colored banner to $stderr in green . [CODESPLIT] def banner ( str , color : GREEN ) now = Time . new . strftime ( \"%H:%M:%S\" ) s = \"#{str} \" . ljust ( 72 , \" \" ) $stderr . puts \"#{color}[#{now}] #{s}#{RESET}\" end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add logger support easy for log monitor when running your app Output errors and valid records count TODO add color support [CODESPLIT] def logger ( options = { records : [ ] , uri : '' , error : '' , type : '' , opts : { } } ) records = options [ :records ] . nil? ? [ ] : options [ :records ] error = options [ :error ] uri = options [ :uri ] type = options [ :type ] opts = options [ :opts ] if defined? Rails if error . present? Rails . logger . info \">>> Error: #{error}\" else Rails . logger . info \">>> Querying Sqoot API V2: #{type}\" Rails . logger . info \">>> #{uri}\" Rails . logger . info \">>> #{opts}\" Rails . logger . info \">>> Hit #{records.count} records\" end else if error . present? puts \">>> Error: #{error}\" puts '' else puts \">>> Querying Sqoot API V2: #{type}\" puts '' puts \">>> #{uri}\" puts '' puts \">>> #{opts}\" puts '' puts \">>> Hit #{records.count} records\" puts '' end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The action [CODESPLIT] def assert_it ( message ) $stderr . puts ( \"Assertion failed: \" + message . to_s ) $stderr . puts ( \"at: \" ) caller . each { | trace | $stderr . puts trace } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "ATTACHED PROCESSES [CODESPLIT] def attach_tick_process ( process , ticks_to_wait = 0 ) self . attached_processes << AttachedProcess . build ( process : process , tickable : true , ticks_waiting : ticks_to_wait ) save! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TOKENS [CODESPLIT] def has_token? ( token ) token && token . _id && self . tokens . where ( _id : token . _id ) . first end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "CONSTRAINTS [CODESPLIT] def add_constraint! ( constraint ) raise PbwArgumentError ( 'Invalid constraint' ) unless constraint return false if has_constraint? ( constraint ) return false unless constraint . before_add ( self ) self . constraints << constraint save! constraint . after_add ( self ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "CAPABILITIES [CODESPLIT] def add_capability! ( capability ) raise PbwArgumentError ( 'Invalid capability' ) unless capability return false if has_capability? ( capability ) return false unless capability . before_add ( self ) self . capabilities << capability save! capability . after_add ( self ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "TRIGGERS [CODESPLIT] def add_trigger! ( trigger ) raise PbwArgumentError ( 'Invalid trigger' ) unless trigger return false if has_trigger? ( trigger ) self . triggers << trigger save! trigger . after_add ( self ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Build a HTTP object having been given a timeout and a URI object Returns Net :: HTTP object . [CODESPLIT] def build_http ( uri , timeout ) http = Net :: HTTP . new ( uri . host , uri . port ) if ( timeout > 0 ) http . open_timeout = timeout http . read_timeout = timeout end return http end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "All responses from openstack where any errors need to be caught are passed through this function . Unless a successful response is passed it will throw a Ropenstack error . If successful returns a hash of response body unless response body is nil then it returns an empty hash . [CODESPLIT] def error_manager ( uri , response ) case response when Net :: HTTPSuccess then # This covers cases where the response may not validate as JSON. begin data = JSON . parse ( response . body ) rescue data = { } end ## Get the Headers out of the response object data [ 'headers' ] = response . to_hash ( ) return data when Net :: HTTPBadRequest raise Ropenstack :: MalformedRequestError , response . body when Net :: HTTPNotFound raise Ropenstack :: NotFoundError , \"URI: #{uri} \\n\" + response . body when Net :: HTTPUnauthorized raise Ropenstack :: UnauthorisedError , response . body else raise Ropenstack :: RopenstackError , response . body end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The function which you call to perform a http request using the request object given in the parameters . By default manage errors is true so all responses are passed through the error manager which converts the into Ropenstack errors . [CODESPLIT] def do_request ( uri , request , manage_errors = true , timeout = 10 ) begin http = build_http ( uri , timeout ) if ( manage_errors ) return error_manager ( uri , http . request ( request ) ) else http . request ( request ) return { \"Success\" => true } end rescue Timeout :: Error raise Ropenstack :: TimeoutError , \"It took longer than #{timeout} to connect to #{uri.to_s}\" rescue Errno :: ECONNREFUSED raise Ropenstack :: TimeoutError , \"It took longer than #{timeout} to connect to #{uri.to_s}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrapper function for a get request just provide a uri and it will return you a hash with the result data . For authenticated transactions a token can be provided . Implemented using the do_request method . [CODESPLIT] def get_request ( uri , token = nil , manage_errors = true ) request = Net :: HTTP :: Get . new ( uri . request_uri , initheader = build_headers ( token ) ) return do_request ( uri , request , manage_errors ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrapper function for delete requests just provide a uri and it will return you a hash with the result data . For authenticated transactions a token can be provided . Implemented using the do_request method . [CODESPLIT] def delete_request ( uri , token = nil , manage_errors = true ) request = Net :: HTTP :: Delete . new ( uri . request_uri , initheader = build_headers ( token ) ) return do_request ( uri , request , manage_errors ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrapper function for a put request just provide a uri and a hash of the data to send then it will return you a hash with the result data . For authenticated transactions a token can be provided . Implemented using the do_request method [CODESPLIT] def put_request ( uri , body , token = nil , manage_errors = true ) request = Net :: HTTP :: Put . new ( uri . request_uri , initheader = build_headers ( token ) ) request . body = body . to_json return do_request ( uri , request , manage_errors ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Wrapper function for a put request just provide a uri and a hash of the data to send then it will return you a hash with the result data . For authenticated transactions a token can be provided . [CODESPLIT] def post_request ( uri , body , token = nil , manage_errors = true ) request = Net :: HTTP :: Post . new ( uri . request_uri , initheader = build_headers ( token ) ) request . body = body . to_json return do_request ( uri , request , manage_errors ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Functional composition f · g [CODESPLIT] def comp ( g ) Fn { | * a , & b | call ( g . call ( a , b ) ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Enumerates articles [CODESPLIT] def articles Enumerator . new do | y | article_ids . each do | id | y << article ( id ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets an article by ID [CODESPLIT] def article ( id ) url = index . knowledgeManagement . articles . article url = url ( url , ArticleID : id ) decorate ( get ( url ) . body ) { | o | autodefine ( o ) } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "BELOW HERE IS OLD CODE THAT MAY OR MAYNOT WORK THAR BE DRAGONS [CODESPLIT] def upload_image_from_file ( name , disk_format , container_format , minDisk , minRam , is_public , file ) data = { \"name\" => name , \"disk_format\" => disk_format , \"container_format\" => container_format , \"minDisk\" => minDisk , \"minRam\" => minRam , \"public\" => is_public } imagesBefore = images ( ) post_request ( address ( \"images\" ) , data , @token , false ) imagesAfter = images ( ) foundNewImage = true image = nil imagesAfter . each do | imageA | imagesBefore . each do | imageB | if ( imageA == imageB ) foundNewImage = false end end if ( foundNewImage ) image = imageA break end end return put_octect ( address ( image [ \"file\" ] ) , file . read , false ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Special rest call for sending a file stream using an octet - stream main change is just custom headers . Still implemented using do_request function . [CODESPLIT] def put_octect ( uri , data , manage_errors ) headers = build_headers ( @token ) headers [ \"Content-Type\" ] = 'application/octet-stream' req = Net :: HTTP :: Put . new ( uri . request_uri , initheader = headers ) req . body = data return do_request ( uri , req , manage_errors , 0 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The rules followed are : 1 . Any live cell with fewer than two live neighbours dies as if caused by under - population . 2 . Any live cell with two or three live neighbours lives on to the next generation . 3 . Any live cell with more than three live neighbours dies as if by overcrowding . 4 . Any dead cell with exactly three live neighbours becomes a live cell as if by reproduction . 5 . Any live cell that is over 3 generations dies [CODESPLIT] def should_cell_live? ( board , cell , x , y ) live_neighbors_count = board . neighbors_of_cell_at ( x , y ) . select { | n | n . alive? } . size case cell . state when :live ( ( 2 .. 3 ) . include? live_neighbors_count ) && ( ! cell . old? ) when :dead live_neighbors_count == 3 end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a path relative to the base path given the full path . This is the inverse of full_path . [CODESPLIT] def relative_path ( path ) path = File . expand_path ( path ) root = full_path ( \"\" ) if path . size >= root . size && path [ 0 ... root . size ] == root path [ 0 ... root . size ] = \"\" path = \"/\" if path . size == 0 path end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Renders an index page for the specified directory . [CODESPLIT] def index ( path ) @entries = [ ] Dir . entries ( path ) . each do | entry | relative_path = relative_path ( File . join ( path , entry ) ) if entry != \".\" && relative_path @entries << { :name => entry , :href => relative_path } end end @path = path haml :index end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": css_extend = > : root_path = > . : scope_name = > rails_xxx : recipe_path = > icons / 16x16 : file_extend = > . png : spacing = > 10 : image_to_folder = > app / assets / images : image_source_folder = > app / assets / images / rails_xxx / sprite_sources : stylesheet_to = > app / assets / stylesheets / rails_xxx / sprite / icons / 16x16 . css . scss . erb : image_to_file_path = > rails_xxx / sprite / icons / 16x16 . png [CODESPLIT] def perform file_infos = [ ] #  puts \"image_source_folder: #{image_source_folder}\" #  puts \"image_to_file_path: #{image_to_file_path}\" #  puts \"stylesheet_to: #{stylesheet_to}\" counter = 0 x = 0 y = 0 max_w = 0 max_h = 0 Dir . entries ( image_source_folder ) . each do | file_name | if file_name != '.' && file_name != '..' && file_name . end_with? ( file_extend ) file_path = \"#{image_source_folder}/#{file_name}\" if :: File . file? ( file_path ) file_name_split = file_name . split ( '.' ) file_name_split . pop file_purename = file_name_split . join ( '.' ) file_info = { :filepath => file_path , :filename => file_name , :file_purename => file_purename , :idx => counter } . merge ( _library . load ( file_path ) ) file_info [ :x ] = x file_info [ :y ] = y y += ( spacing + file_info [ :height ] ) max_w = [ max_w , file_info [ :width ] ] . max max_h = y file_infos << file_info counter += 1 end end end _composite_images ( :file_infos => file_infos , :max_w => max_w , :max_h => max_h ) _composite_css ( file_infos , :max_w => max_w , :max_h => max_h ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new table . [CODESPLIT] def accessors_from_headers! raise \"Can't define accessors from headers in a table without headers\" unless @has_headers self . accessors = headers . map { | val | ( val && ! val . empty? ) ? val . to_s . downcase . tr ( '^a-z0-9_' , '_' ) . squeeze ( '_' ) . gsub ( / \\A \\z / , '' ) . to_sym : nil } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Array<Symbol > Hash<Symbol = > Integer > nil ] accessors [CODESPLIT] def accessors = ( accessors ) @accessor_columns = { } case accessors when nil # nothing to do when Array accessors . each_with_index do | name , idx | @accessor_columns [ name . to_sym ] = idx if name end when Hash @accessor_columns = Hash [ accessors . map { | name , index | [ name . to_sym , index ] } ] else raise ArgumentError , \"Expected nil, an Array or a Hash, but got #{accessors.class}\" end @accessor_columns . freeze @column_accessors = @accessor_columns . invert . freeze @accessors = @column_accessors . values_at ( 0 .. ( @column_accessors . keys . max || - 1 ) ) . freeze end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@return [ Tabledata :: Row ] The row at the given row number ( zero based ) . Includes headers and footer . Returns the given default value or invokes the default block if the desired row does not exist . [CODESPLIT] def fetch_row ( row , * default ) raise ArgumentError , \"Must only provide at max one default value or one default block\" if default . size > ( block_given? ? 0 : 1 ) row_data = row ( row ) if row_data row_data elsif block_given? yield ( self , row ) elsif default . empty? raise KeyError , \"Row not found: #{row.inspect}\" else default . first end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@return [ Object ] The cell value at the given row and column number ( zero based ) . Includes headers and footer . Returns the given default value or invokes the default block if the desired cell does not exist . [CODESPLIT] def fetch_cell ( row , column , * default_value , & default_block ) raise ArgumentError , \"Must only provide at max one default value or one default block\" if default_value . size > ( block_given? ? 0 : 1 ) row_data = row ( row ) if row_data row_data . fetch ( column , default_value , default_block ) elsif block_given? yield ( self , row , column ) elsif default_value . empty? raise IndexError , \"Row not found: #{row.inspect}, #{column.inspect}\" else default_value . first end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Append a row to the table . [CODESPLIT] def << ( row ) index = @data . size begin row = row . to_ary rescue NoMethodError raise ArgumentError , \"Row must be provided as Array or respond to `to_ary`, but got #{row.class} in row #{index}\" unless row . respond_to? ( :to_ary ) raise end raise InvalidColumnCount . new ( index , row . size , column_count ) if @data . first && row . size != @data . first . size @data << row @rows << Row . new ( self , index , row ) self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the method that will place the anchor tag and id of the footnote within the paragraph body itself . [CODESPLIT] def html ( id , time ) inline_footnote_label = Build . tag ( \"span\" , Build . tag ( \"sup\" , id . to_s ) , :class => \"inline-footnote-number\" ) Build . tag ( \"a\" , inline_footnote_label , :href => \"#footnote#{id}#{time}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the method that will actually spit out the div that the footnote s content is in . This will generally be called after all of the paragraph s text has been spit out so that the footnotes can be appended after . Note that it needs to be passed an id from the caller so that it can be linked to corretly with an anchor tag in the body of the main text . [CODESPLIT] def footnote_html ( id , time ) footnote_label = Build . tag ( \"span\" , Build . tag ( \"sup\" , id . to_s ) , :class => \"footnote-number\" ) footnote_content = sequence . elements . map { | s | s . html } . join Build . tag ( \"div\" , footnote_label + footnote_content , :id => \"footnote#{id}#{time}\" , :class => \"footnote\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Database Instance Actions [CODESPLIT] def instance_action ( id , action , param ) case action when \"RESTART\" post_request ( address ( \"/instances/\" + id + \"/action\" ) , { :restart => { } } , @token ) when \"RESIZE\" if param . is_a? String post_request ( address ( \"/instances/\" + id + \"/action\" ) , { :resize => { :flavorRef => param } } , @token ) elsif param . is_a? Int post_request ( address ( \"/instances/\" + id + \"/action\" ) , { :resize => { :volume => { :size => param } } } , @token ) else raise Ropenstack :: RopenstackError , \"Invalid Parameter Passed\" end else raise Ropenstack :: RopenstackError , \"Invalid Action Passed\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Given a Class generate a map of dependencies needed to construct a new instance of that class . Dependencies are looked up ( and / or instantiated as determined within the ObjectContext ) via the provided ObjectContext . [CODESPLIT] def resolve_for_class ( klass , object_context , remapping = nil ) remapping ||= { } klass . object_definition . component_names . inject ( { } ) do | obj_map , name | obj_map [ name ] = search_for ( klass , object_context , remapping [ name . to_sym ] || remapping [ name . to_s ] || name ) obj_map end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "add errors error_on can be a symbol or object instance [CODESPLIT] def add ( error_on , message = \"Unknown error\" ) # humanize error_on if error_on . is_a? ( Symbol ) error_on_str = error_on . to_s else error_on_str = underscore ( error_on . class . name ) end error_on_str = error_on_str . gsub ( / \\/ / , '_' ) error_on_str = error_on_str . gsub ( / / , ' ' ) error_on_str = error_on_str . gsub ( / / , '' ) . strip #error_on_str = error_on_str.capitalize @errors [ error_on_str ] ||= [ ] @errors [ error_on_str ] << message . to_s end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Finds the neighbors of a given { Cell } s co - ordinates . The neighbors are the eight cells that surround the given one . [CODESPLIT] def neighbors_of_cell_at ( x , y ) neighbors = coords_of_neighbors ( x , y ) . map { | x , y | self . cell_at ( x , y ) } neighbors . reject { | n | n . nil? } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the first stage in a Game s #tick . [CODESPLIT] def reformat_for_next_generation! # create an array of dead cells and insert it as the first and last row of cells dead_cells = ( 1 .. @cells . first . size ) . map { Cell . new } # don't forget to deep copy the dead_cells @cells . unshift Marshal . load ( Marshal . dump ( dead_cells ) ) @cells . push Marshal . load ( Marshal . dump ( dead_cells ) ) # also insert a dead cell at the left and right of each row @cells . each do | row | row . unshift Cell . new row . push Cell . new end # validate to see if we broke the board validate end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is the third and last stage in a Game s #tick . [CODESPLIT] def shed_dead_weight! # Remove the first and last rows if all cells are dead @cells . shift if @cells . first . all? { | cell | cell . dead? } @cells . pop if @cells . last . all? { | cell | cell . dead? } # Remove the first cell of every row, if they are all dead first_columns = @cells . map { | row | row . first } if first_columns . all? { | cell | cell . dead? } @cells . each { | row | row . shift } end # Remove the last cell of every row, if they are all dead last_columns = @cells . map { | row | row . last } if last_columns . all? { | cell | cell . dead? } @cells . each { | row | row . pop } end validate end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Calculates the co - ordinates of neighbors of a given pair of co - ordinates . [CODESPLIT] def coords_of_neighbors ( x , y ) coords_of_neighbors = [ ] ( x - 1 ) . upto ( x + 1 ) . each do | neighbors_x | ( y - 1 ) . upto ( y + 1 ) . each do | neighbors_y | next if ( x == neighbors_x ) && ( y == neighbors_y ) coords_of_neighbors << [ neighbors_x , neighbors_y ] end end coords_of_neighbors end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a list of merchants base on the following parameters [CODESPLIT] def merchant ( id , options = { } ) options = update_by_expire_time options if merchant_not_latest? ( id ) @rsqoot_merchant = get ( \"merchants/#{id}\" , options , SqootMerchant ) @rsqoot_merchant = @rsqoot_merchant . merchant if @rsqoot_merchant end logger ( uri : sqoot_query_uri , records : [ @rsqoot_merchant ] , type : 'merchants' , opts : options ) @rsqoot_merchant end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Encode a standard payload to a hybi10 WebSocket frame [CODESPLIT] def encode data , opcode = TEXT_FRAME frame = [ ] frame << ( opcode | 0x80 ) packr = \"CC\" if opcode == TEXT_FRAME data . force_encoding ( \"UTF-8\" ) if ! data . valid_encoding? raise \"Invalid UTF!\" end end # append frame length and mask bit 0x80 len = data ? data . bytesize : 0 if len <= 125 frame << ( len | 0x80 ) elsif len < 65536 frame << ( 126 | 0x80 ) frame << len packr << \"n\" else frame << ( 127 | 0x80 ) frame << len packr << \"L!>\" end # generate a masking key key = rand ( 2 ** 31 ) # mask each byte with the key frame << key packr << \"N\" #puts \"op #{opcode} len #{len} bytes #{data}\" # Apply the masking key to every byte len . times do | i | frame << ( ( data . getbyte ( i ) ^ ( key >> ( ( 3 - ( i % 4 ) ) * 8 ) ) ) & 0xFF ) end frame . pack ( \"#{packr}C*\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method sets up the + Permission + class with all baked in methods . [CODESPLIT] def challah_permission unless included_modules . include? ( InstanceMethods ) include InstanceMethods extend ClassMethods end class_eval do validates_presence_of :name , :key validates_uniqueness_of :name , :key validates_format_of :key , :with => / / , :message => :invalid_key has_many :permission_roles , :dependent => :destroy has_many :roles , :through => :permission_roles , :order => 'roles.name' has_many :permission_users , :dependent => :destroy has_many :users , :through => :permission_users , :order => 'users.last_name, users.first_name' default_scope order ( 'permissions.name' ) attr_accessible :name , :description , :key , :locked after_create :add_to_admin_role end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Parses out the <tt > base_path< / tt > setting from a path to display it in a less verbose way . [CODESPLIT] def display_path ( filename = nil ) filename ||= path display_path = File . expand_path ( filename ) display_path . gsub ( base_path . to_s , \"\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "makes a POST request [CODESPLIT] def post hash = { } , payload raise 'Payload cannot be blank' if payload . nil? || payload . empty? hash . symbolize_keys! call ( :post , hash [ :endpoint ] , ( hash [ :args ] || { } ) . merge ( { :method => :post } ) , payload ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "low level api for request ( needed por PUT PATCH & DELETE methods ) [CODESPLIT] def call method , endpoint , args = { } , params raise \"Endpoint can't be blank\" unless endpoint raise \"Method is missing\" unless method url = ( method == :get || method == :delete ) ? url ( endpoint , params ) : url ( endpoint ) RestClient :: Request . execute ( method : method , url : url , headers : header ( args [ :headers ] ) , payload : params || { } ) do | response , request , result | #status = response.code == 200 ? :debug : :error #print(status, request, response.body) parse ( response , endpoint ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Networks [CODESPLIT] def networks ( id = nil ) endpoint = \"networks\" unless id . nil? endpoint = endpoint + \"/\" + id end return get_request ( address ( endpoint ) , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new network on Openstack given a name and tenant id . [CODESPLIT] def create_network ( name , tenant , admin_state_up = true ) data = { 'network' => { 'name' => name , 'tenant_id' => tenant , 'admin_state_up' => admin_state_up } } return post_request ( address ( \"networks\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new port given network and device ids optional parameter subnet id allows for scoping the port to a single subnet . [CODESPLIT] def create_port ( network , subnet = nil , device = nil , device_owner = nil ) data = { 'port' => { 'network_id' => network , } } unless device_owner . nil? data [ 'port' ] [ 'device_owner' ] = device_owner end unless device . nil? data [ 'port' ] [ 'device_id' ] = device end unless subnet . nil? data [ 'port' ] [ 'fixed_ips' ] = [ { 'subnet_id' => subnet } ] end puts data return post_request ( address ( \"ports\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Weird function for adding a port to multiple subnets if nessessary . [CODESPLIT] def move_port_to_subnets ( port_id , subnet_ids ) id_list = Array . new ( ) subnet_ids . each do | id | id_list << { \"subnet_id\" => id } end return update_port ( port_id , id_list ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is a convenience method that sets the Content - Type headers and writes the JSON String to the response . [CODESPLIT] def json ( data = { } , options = { } ) response [ CONTENT_TYPE ] = APPLICATION_JSON response . status = options [ :status ] if options . has_key? ( :status ) response . write self . class . json_serializer . dump ( data ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This is a convenience method that forms an absolute URL based on the url parameter which can be a relative or absolute URL and then sets the headers and the body appropriately to do a 302 redirect . [CODESPLIT] def redirect_to ( url , options = { } ) full_url = absolute_url ( url , options ) response [ LOCATION ] = full_url respond_with 302 full_url end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "+ name + ( Symbol ) : name for method + types + ( Array ) : array with types for method arguments + body + ( Proc ) : block called with method [CODESPLIT] def eql0? ( other ) #:nodoc: @ancestors . find { | a | a . __overload_methods . find { | m | m . name == other . name && m . types == other . types } } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Serialize [CODESPLIT] def as_json ( opts = { } ) raise NotImplementedError , 'as_json with arguments' unless opts . empty? { } . tap do | h | attributes . each do | attr , val | h [ attr ] = val . as_json end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Gets a list of servers from OpenStack [CODESPLIT] def servers ( id ) endpoint = \"/servers\" unless id . nil? endpoint = endpoint + \"/\" + id end return get_request ( address ( endpoint ) , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Creates a server on OpenStack . [CODESPLIT] def create_server ( name , image , flavor , networks = nil , keypair = nil , security_group = nil , metadata = nil ) data = { \"server\" => { \"name\" => name , \"imageRef\" => image , \"flavorRef\" => flavor , } } unless networks . nil? data [ \"server\" ] [ \"networks\" ] = networks end unless keypair . nil? data [ \"server\" ] [ \"key_name\" ] = keypair end unless security_group . nil? data [ \"server\" ] [ \"security_group\" ] = security_group end return post_request ( address ( \"/servers\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Perform an action on a server on Openstack by passing an id and an action some actions require more data . [CODESPLIT] def action ( id , act , * args ) data = case act when \"reboot\" then { 'reboot' => { \"type\" => args [ 0 ] } } when \"vnc\" then { 'os-getVNCConsole' => { \"type\" => \"novnc\" } } when \"stop\" then { 'os-stop' => 'null' } when \"start\" then { 'os-start' => 'null' } when \"pause\" then { 'pause' => 'null' } when \"unpause\" then { 'unpause' => 'null' } when \"suspend\" then { 'suspend' => 'null' } when \"resume\" then { 'resume' => 'null' } when \"create_image\" then { 'createImage' => { 'name' => args [ 0 ] , 'metadata' => args [ 1 ] } } else raise \"Invalid Action\" end return post_request ( address ( \"/servers/\" + id + \"/action\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete an image stored on Openstack through the nova endpoint [CODESPLIT] def delete_image ( id ) uri = URI . parse ( \"http://\" + @location . host + \":\" + @location . port . to_s + \"/v2/images/\" + id ) return delete_request ( uri , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get method use by all other API qeury methods fetch records from the Sqoot API V2 url and provide wrapper functionality [CODESPLIT] def get ( path , opts = { } , wrapper = :: Hashie :: Mash ) uri , headers = url_generator ( path , opts ) begin json = JSON . parse uri . open ( headers ) . read result = wrapper . new json @query_options = result . query result rescue => e logger ( error : e ) nil end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Generate valid Sqoot API V2 url and provide two different way of authentication : : header : parameter [CODESPLIT] def url_generator ( path , opts = { } , require_key = false ) uri = URI . parse base_api_url headers = { read_timeout : read_timeout } uri . path = '/v2/' + path query = options_parser opts endpoint = path . split ( '/' ) [ 0 ] case authentication_method when :header headers . merge! 'Authorization' => \"api_key #{api_key(endpoint)}\" query += \"&api_key=#{api_key(endpoint)}\" if require_key when :parameter query += \"&api_key=#{api_key(endpoint)}\" end uri . query = query @sqoot_query_uri = uri [ uri , headers ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Decide which api key should be used : private public [CODESPLIT] def api_key ( endpoint = '' ) if private_endpoints . include? endpoint private_api_key elsif public_endpoints . include? endpoint public_api_key else fail \"No such endpoint #{endpoint} available.\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Example : options = { per_page : 10 page : 1 } Options should be parsed as http query : per_page = 10&page = 1 [CODESPLIT] def options_parser ( options = { } ) query = options . map do | key , value | [ key , value ] . map ( :to_s ) . join ( '=' ) end . join ( '&' ) URI . encode query end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "translations [CODESPLIT] def build_translations # if is_translated langs = Language . list_with_default else langs = [ '' ] end # langs_missing = langs - self . translations . all . map { | r | r . lang } langs_missing . each do | lang | self . translations . new ( :lang => lang ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "content [CODESPLIT] def content ( lang = '' ) filename = fullpath ( lang ) return nil if filename . nil? return '' if ! File . exists? filename File . read ( filename ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "operations with path [CODESPLIT] def set_basepath if self . parent . nil? self . basepath = self . basename self . basedirpath ||= '' else self . basepath = self . parent . basepath + '/' + self . basename self . basedirpath ||= self . parent . basepath + '/' end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "callbacks [CODESPLIT] def _before_validation fix_basedirpath # parent, basedirpath if self . parent_id . nil? && ! self . basedirpath . blank? set_parent_from_basedirpath elsif self . basedirpath . nil? && ! self . parent_id . nil? set_basedirpath_from_parent end set_basepath end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve information of commissions based on the following parameters [CODESPLIT] def commissions ( options = { } ) options = update_by_expire_time options if commissions_not_latest? ( options ) @rsqoot_commissions = get ( 'commissions' , options , SqootCommission ) @rsqoot_commissions = @rsqoot_commissions . commissions if @rsqoot_commissions end logger ( uri : sqoot_query_uri , records : @rsqoot_commissions , type : 'commissions' , opts : options ) @rsqoot_commissions end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "import templates [CODESPLIT] def reviewimport_templates # input @dirname = params [ :dirname ] # work @backup_basedir = Optimacms :: BackupMetadata :: Backup . make_backup_dir_path @dirname @backup_templates_dirpath = File . join ( @backup_basedir , \"templates\" ) @analysis = Optimacms :: BackupMetadata :: TemplateImport . analyze_data_dir ( @backup_templates_dirpath ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "import pages [CODESPLIT] def reviewimport_pages # input @dirname = params [ :dirname ] # work @backup_basedir = Optimacms :: BackupMetadata :: Backup . make_backup_dir_path @dirname @backup_templates_dirpath = File . join ( @backup_basedir , \"pages\" ) @analysis = Optimacms :: BackupMetadata :: PageImport . analyze_data_dir ( @backup_templates_dirpath ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List all available leagues . [CODESPLIT] def leagues ( opts = { } ) season = opts . fetch ( :season ) { Time . now . year } json_response get ( \"competitions/?season=#{season}\" ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Show League Table / current standing . Filters : [CODESPLIT] def league_table ( id , opts = { } ) raise IdMissingError , 'missing id' if id . nil? match_day = opts [ :match_day ] uri = \"competitions/#{id}/leagueTable/\" url = match_day . nil? ? uri : \"#{uri}?matchday=#{match_day}\" json_response get ( url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List all fixtures for a certain league . Filters : [CODESPLIT] def league_fixtures ( id , opts = { } ) raise IdMissingError , 'missing id' if id . nil? time_frame = opts [ :time_frame ] match_day = opts [ :match_day ] uri = \"competitions/#{id}/fixtures/\" url = time_frame . nil? ? uri : \"#{uri}?timeFrame=#{time_frame}\" url = match_day . nil? ? url : \"#{url}?matchday=#{match_day}\" json_response get ( url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "List fixtures across a set of leagues . Filters : [CODESPLIT] def fixtures ( opts = { } ) time_frame = opts [ :time_frame ] league = opts [ :league ] uri = \"fixtures/\" url = time_frame . nil? ? uri : \"#{uri}?timeFrame=#{time_frame}\" url = league . nil? ? url : \"#{url}?league=#{league}\" json_response get ( url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Show one fixture . Filters : [CODESPLIT] def fixture ( id , opts = { } ) raise IdMissingError , 'missing id' if id . nil? head2head = opts [ :head2head ] uri = \"fixtures/#{id}/\" url = head2head . nil? ? uri : \"#{uri}?head2head=#{head2head}\" json_response get ( url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Show all fixtures for a certain team . Filters : [CODESPLIT] def team_fixtures ( id , opts = { } ) raise IdMissingError , 'missing id' if id . nil? season = opts [ :season ] time_frame = opts [ :time_frame ] venue = opts [ :venue ] uri = \"teams/#{id}/fixtures/\" url = season . nil? ? uri : \"#{uri}?season=#{season}\" url = time_frame . nil? ? url : \"#{url}?timeFrame=#{time_frame}\" url = venue . nil? ? url : \"#{url}?venue=#{venue}\" json_response get ( url ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add match method which work like case statement but for types [CODESPLIT] def match ( * args , & block ) z = Module . new do include Ov extend self def try ( * args , & block ) let :anon_method , args , block end def otherwise ( & block ) let :otherwise , block end instance_eval block end begin z . anon_method ( args ) rescue Ov :: NotImplementError => e z . otherwise end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "GET / pages / new [CODESPLIT] def new @page = Page . new ( path : '/' ) if params [ :path ] . present? @page . path = CGI :: unescape ( params [ :path ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Tries to return the value of the column identified by index corresponding accessor or header . It throws an IndexError exception if the referenced index lies outside of the array bounds . This error can be prevented by supplying a second argument which will act as a default value . [CODESPLIT] def fetch ( column , * default_value , & default_block ) raise ArgumentError , \"Must only provide at max one default value or one default block\" if default_value . size > ( block_given? ? 0 : 1 ) index = case column when Symbol then @table . index_for_accessor ( column ) when String then @table . index_for_header ( column ) when Integer then column else raise InvalidColumnSpecifier , \"Invalid index type, expected Symbol, String or Integer, but got #{column.class}\" end @data . fetch ( index , default_value , default_block ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Convenience access of values in the row . Can either be used like Array# [] i . e . it accepts an offset an offset + length or an offset - to - offset range . Alternatively you can use a Symbol if it s a valid accessor in this table . And the last variant is using a String which will access the value of the corresponding header . [CODESPLIT] def [] ( a , b = nil ) if b || a . is_a? ( Range ) then slice ( a , b ) else at ( a ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Access a single cell by either index index - range accessor or header - name . [CODESPLIT] def at ( column ) case column when Symbol then at_accessor ( column ) when String then at_header ( column ) when Integer then at_index ( column ) when Range then @data [ column ] else raise InvalidColumnSpecifier , \"Invalid index type, expected Symbol, String or Integer, but got #{column.class}\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Access multiple values by either index index - range accessor or header - name . [CODESPLIT] def values_at ( * columns ) result = [ ] columns . each do | column | data = at ( column ) if column . is_a? ( Range ) result . concat ( data ) if data else result << data end end result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Allow reading and writing cell values by their accessor name . [CODESPLIT] def method_missing ( name , * args , & block ) return super unless @table . accessors? name =~ / \\w / name_mod , assign = $1 , $2 index = @table . index_for_accessor ( name_mod ) arg_count = assign ? 1 : 0 return super unless index raise ArgumentError , \"Wrong number of arguments (#{args.size} for #{arg_count})\" if args . size > arg_count if assign then @data [ index ] = args . first else @data [ index ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Providers must define an authorize method . This is used to initialize and set authentication parameters to access the API [CODESPLIT] def authorize ( auth = { } ) @authentication ||= TaskMapper :: Authenticator . new ( auth ) auth = @authentication if ( auth . account . nil? and auth . subdomain . nil? ) or auth . username . nil? or auth . password . nil? raise \"Please provide at least an account (subdomain), username and password)\" end UnfuddleAPI . protocol = auth . protocol if auth . protocol? UnfuddleAPI . account = auth . account || auth . subdomain UnfuddleAPI . authenticate ( auth . username , auth . password ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": ": nodoc : [CODESPLIT] def b64_encode ( string ) if Base64 . respond_to? ( :strict_encode64 ) Base64 . strict_encode64 ( string ) else # Fall back to stripping out newlines on Ruby 1.8. Base64 . encode64 ( string ) . gsub ( / \\n / , '' ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method initialize ( api_key = get_api_key_from_env ) Constructor method @param api_key [ String ] ( see api_key ) @return [ Reliquary :: Client ] the initialized client [CODESPLIT] def parse ( json ) begin # strip off some layers of nonsense added by Oj MultiJson . load ( json , :symbolize_keys => true ) . values [ 0 ] rescue StandardError => e raise e end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@!method method_missing ( method_name * args &block ) Delegate HTTP method calls to RestClient :: Resource [CODESPLIT] def method_missing ( method_name , * args , & block ) begin self . api_base . send ( method_name . to_sym , args , block ) rescue StandardError => e raise e end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a watch for a shallow change in the contents ( attributes elements or key - value pairs ) of one or more reactive objects . [CODESPLIT] def on_change_in ( * args , except : nil , & block ) args . each do | arg | ensure_reactive ( arg ) traverse ( arg , :shallow , except , args . size > 1 || block . arity == 3 , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Does a deep traversal of all values reachable from the given root object ( s ) . [CODESPLIT] def on_deep_change_in ( * roots , except : nil , & block ) roots . each do | root | ensure_reactive ( root ) traverse ( root , :node , except , true , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Must behave like a Volt :: Model and respond to #get ( attribute ) [CODESPLIT] def reactive_model? ( model ) Volt :: Model === model || # dirty way of letting anything be reactive if it wants ( model . respond_to? ( :reactive_model? ) && model . reactive_model? ) || ( model . class . respond_to? ( :reactive_model? ) && model . class . reactive_model? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Must behave like a Volt :: ArrayModel or Volt :: ReactiveArray [CODESPLIT] def reactive_array? ( model ) Volt :: ArrayModel === model || Volt :: ReactiveArray === model || # dirty way of letting anything be reactive if it wants ( model . respond_to? ( :reactive_array? ) && model . reactive_array? ) || ( model . class . respond_to? ( :reactive_array? ) && model . class . reactive_array? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Must behave like a Volt :: ReactiveHash [CODESPLIT] def reactive_hash? ( model ) Volt :: ReactiveHash === model || # dirty way of letting anything be reactive if it wants ( model . respond_to? ( :reactive_hash? ) && model . reactive_hash? ) || ( model . class . respond_to? ( :reactive_hash? ) && model . class . reactive_hash? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "method_option : person : aliases = > - p : desc = > Delete the file after parsing it [CODESPLIT] def create ( message = \"\" ) if \"help\" == message invoke ( :help , [ \"create\" ] ) ; exit 0 end if File . pipe? ( STDIN ) || File . select ( [ STDIN ] , [ ] , [ ] , 0 ) != nil then message = STDIN . readlines ( ) . join ( \"\" ) end url = \"https://api.pushbullet.com/v2/pushes\" token = Utils :: get_token ( options ) unless message . empty? args = Utils :: get_push_args ( options ) args [ 'body' ] = message Utils :: send ( url , token , \"post\" , args ) else puts \"Nothing to do.\" end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a new secondary index to this model . Default option is : type = > : int can also be : bin Default option is : multi = > false can also be true Option : map can be used to map the index to a model ( see map_model ) . This assumes by default that the index name ends in _id ( use : map = > true ) If it ends in something else use : map = > _suffix [CODESPLIT] def index2i ( name , opts = { } ) name = name . to_s opts . replace ( { :type => :int , :multi => false , :finder => :find } . merge ( opts ) ) indexes2i [ name ] = opts class_eval %Q{\n        def #{name}\n          @indexes2i['#{name}']\n        end\n\n        def #{name}=(value)\n          @indexes2i['#{name}'] = value\n        end\n      } if opts [ :map ] if opts [ :map ] === true # assume that it ends in _id model_name = name [ 0 .. - 4 ] map_model ( model_name , opts ) else model_name = name [ 0 .. - ( opts [ :map ] . length + 1 ) ] map_model ( model_name , opts . merge ( :suffix => opts [ :map ] ) ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The map_model method is a convenience method to map the model_id to getters and setters . The assumption is that you have a value or index2i for model_id . The default suffix is _id so map_model : promotion implies that promotion_id is the index2i . [CODESPLIT] def map_model ( model_name , opts = { } ) model_name = model_name . to_s class_name = Risky :: Inflector . classify ( model_name ) opts . replace ( { :type => :index2i , :suffix => '_id' } . merge ( opts ) ) class_eval %Q{\n        def #{model_name}\n          @#{model_name} ||= #{class_name}.#{opts[:finder]} #{model_name}#{opts[:suffix]}\n        end\n\n        def #{model_name}=(value)\n          @#{model_name} = value\n          self.#{model_name}#{opts[:suffix]} = value.nil? ? nil : value.id\n        end\n\n        def #{model_name}_id=(value)\n          @#{model_name} = nil if self.#{model_name}_id != value\n          indexes2i['#{model_name}#{opts[:suffix]}'] = value\n        end\n      } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get a list of a tenants routers [CODESPLIT] def routers ( id = nil ) endpoint = \"routers\" unless id . nil? endpoint = endpoint + \"/\" + id end return get_request ( address ( endpoint ) , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Create a new router with a given name . [CODESPLIT] def create_router ( name , admin_state_up = true ) data = { 'router' => { 'name' => name , 'admin_state_up' => admin_state_up , } } return post_request ( address ( \"routers\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Delete a connection between a subnet and router given either port or subnet ids . [CODESPLIT] def delete_router_interface ( router , id , type ) data = case type when 'port' then { 'port_id' => id } when 'subnet' then { 'subnet_id' => id } else raise \"Invalid Interface Type\" end return put_request ( address ( \"routers/\" + router + \"/remove_router_interface\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "find in self find in ancestors find types find any types [CODESPLIT] def where ( method ) @complete , @result = nil , nil z = find_or_next ( method ) { | method | self . find { | m | m . eql? ( method ) } } . find_or_next ( method ) { | method | self . find { | m | m . eql0? ( method ) } } . find_or_next ( method ) { | method | self . find { | m | m . like? ( method ) } } . find_or_next ( method ) { | method | self . find { | m | m . like0? ( method ) } } . get end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "load config from files [CODESPLIT] def load config_files . each do | file | config = YAML :: load ( File . open ( file ) ) @config . merge! config end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a list of providers base on the following parameters [CODESPLIT] def providers ( options = { } ) options = update_by_expire_time options query = options . delete ( :query ) if providers_not_latest? ( options ) @rsqoot_providers = get ( 'providers' , options , SqootProvider ) @rsqoot_providers = @rsqoot_providers . providers . map ( :provider ) if @rsqoot_providers end result = query . present? ? query_providers ( query ) : @rsqoot_providers logger ( uri : sqoot_query_uri , records : result , type : 'providers' , opts : options ) result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a list of categories base on the following parameters [CODESPLIT] def categories ( options = { } ) options = update_by_expire_time options query = options . delete ( :query ) if categories_not_latest? ( options ) @rsqoot_categories = get ( 'categories' , options , SqootCategory ) @rsqoot_categories = @rsqoot_categories . categories . map ( :category ) if @rsqoot_categories end result = query . present? ? query_categories ( query ) : @rsqoot_categories logger ( uri : sqoot_query_uri , records : result , type : 'categories' , opts : options ) result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This method sets up the + Role + class with all baked in methods . [CODESPLIT] def challah_role unless included_modules . include? ( InstanceMethods ) include InstanceMethods extend ClassMethods end class_eval do # Validations ################################################################ validates :name , :presence => true , :uniqueness => true # Relationships ################################################################ has_many :permission_roles , :dependent => :destroy has_many :permissions , :through => :permission_roles , :order => 'permissions.name' has_many :users , :order => 'users.first_name, users.last_name' # Scoped Finders ################################################################ default_scope order ( 'roles.name' ) # Callbacks ################################################################ after_save :save_permission_keys # Attributes ################################################################ attr_accessible :description , :default_path , :locked , :name end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "def nil_if_blank self . trial_end = nil if self . trial_end . blank? end [CODESPLIT] def check_for_upgrade if plan_id_changed? old_plan = Plan . find ( plan_id_was ) if plan_id_was . present? self . upgraded = true if old_plan . nil? || old_plan . order < plan . order end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "if chainable method or returns self for some other reason return this proxy instead [CODESPLIT] def method_missing ( name , * args , & block ) obj = __getobj__ __substitute_self__ ( obj . __send__ ( name , args , block ) , obj ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a list of deals based on the following parameters [CODESPLIT] def deals ( options = { } ) options = update_by_expire_time options if deals_not_latest? ( options ) uniq = ! ! options . delete ( :uniq ) @rsqoot_deals = get ( 'deals' , options , SqootDeal ) || [ ] @rsqoot_deals = @rsqoot_deals . deals . map ( :deal ) unless @rsqoot_deals . empty? @rsqoot_deals = uniq_deals ( @rsqoot_deals ) if uniq end logger ( uri : sqoot_query_uri , records : @rsqoot_deals , type : 'deals' , opts : options ) @rsqoot_deals end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Retrieve a deal by id [CODESPLIT] def deal ( id , options = { } ) options = update_by_expire_time options if deal_not_latest? ( id ) @rsqoot_deal = get ( \"deals/#{id}\" , options , SqootDeal ) @rsqoot_deal = @rsqoot_deal . deal if @rsqoot_deal end logger ( uri : sqoot_query_uri , records : [ @rsqoot_deal ] , type : 'deal' , opts : options ) @rsqoot_deal end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Auto Increment for deals query . [CODESPLIT] def total_sqoot_deals ( options = { } ) @total_deals ||= [ ] @cached_pages ||= [ ] page = options [ :page ] || 1 check_query_change options unless page_cached? page @total_deals += deals ( options ) @total_deals . uniq! @cached_pages << page . to_s @cached_pages . uniq! end @total_deals end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Uniq deals from Sqoot because there are some many duplicated deals with different ids Simplely distinguish them by their titles [CODESPLIT] def uniq_deals ( deals = [ ] ) titles = deals . map ( :title ) . uniq titles . map do | title | deals . map do | deal | deal if deal . try ( :title ) == title end . compact . last end . flatten end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "A status checker for method : total_sqoot_deals If the query parameters changed this will reset the cache else it will do nothing [CODESPLIT] def check_query_change ( options = { } ) options = update_by_expire_time options @last_deals_query ||= '' current_query = options [ :query ] . to_s current_query += options [ :category_slugs ] . to_s current_query += options [ :location ] . to_s current_query += options [ :radius ] . to_s current_query += options [ :online ] . to_s current_query += options [ :expired_in ] . to_s current_query += options [ :per_page ] . to_s if @last_deals_query != current_query @last_deals_query = current_query @total_deals = [ ] @cached_pages = [ ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Read cookies from Mozilla cookies . txt - style IO stream [CODESPLIT] def load_cookies ( file ) now = :: Time . now io = case file when String open ( file ) else file end io . each_line do | line | line . chomp! line . gsub! ( / / , '' ) fields = line . split ( \"\\t\" ) next if fields . length != 7 name , value , domain , for_domain , path , secure , version = fields [ 5 ] , fields [ 6 ] , fields [ 0 ] , ( fields [ 1 ] == \"TRUE\" ) , fields [ 2 ] , ( fields [ 3 ] == \"TRUE\" ) , 0 expires_seconds = fields [ 4 ] . to_i expires = ( expires_seconds == 0 ) ? nil : :: Time . at ( expires_seconds ) next if expires and ( expires < now ) cookies . add ( name , value , domain : domain , path : path , expires : expires , secure : secure ) end io . close if String === file self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Write cookies to Mozilla cookies . txt - style IO stream [CODESPLIT] def dump_cookies ( file ) io = case file when String open ( file , \"w\" ) else file end cookies . to_a . each do | cookie | io . puts ( [ cookie [ :domain ] , \"FALSE\" , # for_domain cookie [ :path ] , cookie [ :secure ] ? \"TRUE\" : \"FALSE\" , cookie [ :expires ] . to_i . to_s , cookie [ :name ] , cookie [ :value ] ] . join ( \"\\t\" ) ) end io . close if String === file self end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "quick set value . [CODESPLIT] def set2 ( selector , value = nil ) elem = element ( xpath : selector ) . to_subtype case elem when Watir :: Radio elem . set when Watir :: Select elem . select value when Watir :: Input elem . set value when Watir :: TextArea elem . set value else elem . click end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add expired time functionality to this gem By default is 1 . hour and can be replaced anywhere [CODESPLIT] def update_by_expire_time ( options = { } ) @expired_in = options [ :expired_in ] if options [ :expired_in ] . present? time = Time . now . to_i / expired_in . to_i options . merge ( expired_in : time ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Make a GET API call with the current path value and [CODESPLIT] def get ( options = { } ) uri = new_uri params = merge_params ( options ) uri . query = URI . encode_www_form ( params ) Net :: HTTP . start ( uri . host , uri . port , :use_ssl => uri . scheme == 'https' ) do | http | request = Net :: HTTP :: Get . new ( uri ) response = http . request ( request ) unless response . is_a? ( Net :: HTTPSuccess ) raise \"#{response.code} #{response.message}\\n#{response.body}\" end return response . body end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "layout [CODESPLIT] def newlayout @item = model . new ( { :tpl_format => Optimacms :: Template :: EXTENSION_DEFAULT , :type_id => TemplateType :: TYPE_LAYOUT } ) item_init_parent @item . set_basedirpath_from_parent @url_back = url_list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "block [CODESPLIT] def newblock @item = model . new ( { :tpl_format => Optimacms :: Template :: EXTENSION_DEFAULT , :type_id => TemplateType :: TYPE_BLOCKVIEW } ) item_init_parent @item . set_basedirpath_from_parent @url_back = url_list end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "folders [CODESPLIT] def newfolder @item = model . new ( :is_folder => true ) item_init_parent @item . basedirpath = @item . parent . basepath + '/' unless @item . parent_id . nil? end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "No ID provided - Lists details for available images . ID provided - Shows the image details as headers and the image binary in the body . [CODESPLIT] def images ( id , tenant_id ) if id . nil? return get_request ( address ( tenant_id , \"images/detail\" ) , @token ) else return get_request ( address ( tenant_id , \"images/\" + id ) , @token ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Registers a virtual machine image . [CODESPLIT] def image_create ( name , disk_format , container_format , create_image , tenant_id ) data = { :name => name , :disk_format => disk_format , :container_format => container_format } unless create_image . nil? data [ :create_image ] = create_image end post_request ( address ( tenant_id , \"images\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replaces the membership list for an image . [CODESPLIT] def replace_memberships ( id , memberships , tenant_id ) data = { :memberships => memberships } put_request ( address ( tenant_id , \"images/\" + id + \"/members\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Adds a member to an image . [CODESPLIT] def add_member ( id , member_id , can_share , tenant_id ) if can_share . nil? data = { :member => { :can_share => false } } else data = { :member => { :can_share => can_share } } end put_request ( address ( tenant_id , \"images/\" + id + \"/members/\" + member_id ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like mkdir - p + dir + . If + owner + is specified the directory will be chowned to owner . If + mode + is specified the directory will be chmodded to mode . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def mkdir ( dir , owner : nil , mode : nil ) FileUtils . mkdir_p ( dir , verbose : verbose? ) chown ( dir , owner ) if owner chmod ( dir , mode ) if mode end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like cp - pr + src + + dst . If + mkdir + is true the dst directoy will be created if necessary before the copy . If + owner + is specified the directory will be chowned to owner . If + mode + is specified the directory will be chmodded to mode . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def cp ( src , dst , mkdir : false , owner : nil , mode : nil ) mkdir_if_necessary ( File . dirname ( dst ) ) if mkdir FileUtils . cp_r ( src , dst , preserve : true , verbose : verbose? ) chown ( dst , owner ) if owner && ! File . symlink? ( dst ) chmod ( dst , mode ) if mode end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like mv + src + + dst . If + mkdir + is true the dst directoy will be created if necessary before the copy . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def mv ( src , dst , mkdir : false ) mkdir_if_necessary ( File . dirname ( dst ) ) if mkdir FileUtils . mv ( src , dst , verbose : verbose? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like ln - sf + src + + dst . The command will be printed out if verbose? . [CODESPLIT] def ln ( src , dst ) FileUtils . ln_sf ( src , dst , verbose : verbose? ) rescue Errno :: EEXIST => e # It's a race - this can occur because ln_sf removes the old # dst, then creates the symlink. Raise if they don't match. raise e if ! ( File . symlink? ( dst ) && src == File . readlink ( dst ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs #mkdir but ONLY if + dir + doesn t already exist . Returns true if directory had to be created . This is useful with verbose? to get an exact changelog . [CODESPLIT] def mkdir_if_necessary ( dir , owner : nil , mode : nil ) return if File . exist? ( dir ) || File . symlink? ( dir ) mkdir ( dir , owner : owner , mode : mode ) true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs #cp but ONLY if + dst + doesn t exist or differs from + src + . Returns true if the file had to be copied . This is useful with verbose? to get an exact changelog . [CODESPLIT] def cp_if_necessary ( src , dst , mkdir : false , owner : nil , mode : nil ) return if File . exist? ( dst ) && FileUtils . compare_file ( src , dst ) cp ( src , dst , mkdir : mkdir , owner : owner , mode : mode ) true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Runs #ln but ONLY if + dst + isn t a symlink or differs from + src + . Returns true if the file had to be symlinked . This is useful with verbose? to get an exact changelog . [CODESPLIT] def ln_if_necessary ( src , dst ) if File . symlink? ( dst ) return if src == File . readlink ( dst ) rm ( dst ) end ln ( src , dst ) true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like chown user : user file . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def chown ( file , user ) # who is the current owner? @scripto_uids ||= { } @scripto_uids [ user ] ||= Etc . getpwnam ( user ) . uid uid = @scripto_uids [ user ] return if File . stat ( file ) . uid == uid FileUtils . chown ( uid , uid , file , verbose : verbose? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like chmod mode file . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def chmod ( file , mode ) return if File . stat ( file ) . mode == mode FileUtils . chmod ( mode , file , verbose : verbose? ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Like rm - rf && mkdir - p . Like all file commands the operation will be printed out if verbose? . [CODESPLIT] def rm_and_mkdir ( dir ) raise \"don't do this\" if dir == \"\" FileUtils . rm_rf ( dir , verbose : verbose? ) mkdir ( dir ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Copy mode atime and mtime from + src + to + dst + . This one is rarely used and doesn t echo . [CODESPLIT] def copy_metadata ( src , dst ) stat = File . stat ( src ) File . chmod ( stat . mode , dst ) File . utime ( stat . atime , stat . mtime , dst ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Atomically write to + path + . An open temp file is yielded . [CODESPLIT] def atomic_write ( path ) tmp = Tempfile . new ( File . basename ( path ) ) yield ( tmp ) tmp . close chmod ( tmp . path , 0o644 ) mv ( tmp . path , path ) ensure rm_if_necessary ( tmp . path ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "can be initialized from the following sources : - a WordTree :: Disk :: Library object - an open File object ( containing a list of files or paths to books ) - a String directory ( presumed to be the library on disk ) - a String file ( containing a list of files or paths to books ) [CODESPLIT] def iterable_from_source ( source ) case source when WordTree :: Disk :: Library then source when File then source . read . split ( \"\\n\" ) . tap do | file | file . close end when String then if File . directory? ( source ) WordTree :: Disk :: Library . new ( source ) elsif File . exist? ( source ) IO . read ( source ) . split ( \"\\n\" ) else raise Errno :: ENOENT , \"Unable to find source for BookList, #{source.inspect}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "This implementation is what I m loosely calling type 1 or regular object creation : - Assume we re looking for a class to create an instance with - it may or may not have a declared list of named objects it needs to be constructed with [CODESPLIT] def type_1_constructor ( klass , name , object_context , overrides = nil ) klass ||= class_finder . find_class ( name ) if ! klass . object_peers . empty? anchor_object_peers object_context , klass . object_peers end constructor_func = nil if klass . has_object_definition? object_map = dependency_resolver . resolve_for_class ( klass , object_context , overrides ) constructor_func = lambda do klass . new ( object_map ) end elsif Utilities . has_zero_arg_constructor? ( klass ) # Default construction constructor_func = lambda do klass . new end else # Oops, out of ideas on how to build. raise ArgumentError . new ( \"Class #{klass} has no special component needs, but neither does it have a zero-argument constructor.\" ) ; end object = nil Conject . override_object_context_with object_context do begin object = constructor_func . call rescue Exception => ex origin = \"#{ex.message}\\n\\t#{ex.backtrace.join(\"\\n\\t\")}\" name ||= \"(no name)\" raise \"Error while constructing object '#{name}' of class #{klass}: #{origin}\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Should be run by another thread - respond to all queued requests [CODESPLIT] def handle_requests until @requestmq . empty? request = @requestmq . deq ( true ) begin request . response = @app . call ( request . env ) rescue Exception => e request . exception = e ensure body = request . response . try ( :last ) body . close if body . respond_to? :close end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Similar to Tabledata :: Table# [] but only returns values for this column . Provides array like access to this column s data . Only considers body values ( i . e . does not consider header and footer ) . [CODESPLIT] def [] ( * args ) rows = @table . body [ args ] if rows . is_a? ( Array ) # slice rows . map { | row | row [ @index ] } else # single row rows [ @index ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "@param [ Hash ] options @option options [ Symbol ] : include_header Defaults to true . If set to false the header ( if present ) is excluded . @option options [ Symbol ] : include_footer Defaults to true . If set to false the footer ( if present ) is excluded . [CODESPLIT] def to_a ( options = nil ) data = @table . data . transpose [ @index ] if options start_offset = options [ :include_header ] && @table . headers? ? 1 : 0 end_offset = options [ :include_footer ] && @table . footer? ? - 2 : - 1 data [ start_offset .. end_offset ] else data end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a new folder to [CODESPLIT] def add_shared_folder ( folders ) folders = Array ( folders ) # can't use dig() might not be ruby 2.3 if ! @config . has_key? ( \"folders\" ) @config [ \"folders\" ] = [ ] end # all paths must be fully qualified.  If we were asked to do a relative path, change # it to the current directory since that's probably what the user wanted.  Not right? # user supply correct path! folders . each { | folder | if ! folder . start_with? '/' folder = \"#{Dir.pwd}/#{folder}\" end @config [ \"folders\" ] << folder } end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return a hash of the configfile or empty hash if error encountered [CODESPLIT] def configfile_hash config = { } begin json = File . read ( configfile ) config = JSON . parse ( json ) rescue Errno :: ENOENT # depending on whether the instance has been saved or not, we may not # yet have a configfile - allow to proceed @logger . debug \"#{configfile} does not exist\" @force_save = true rescue JSON :: ParserError # swallow parse errors so that we can destroy and recreate automatically @logger . debug \"JSON parse error in #{configfile}\" @force_save = true end config end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Accounts [CODESPLIT] def account ( id , head ) if head get_request ( address ( id ) , @token ) else head_request ( address ( id ) , @token ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Containers [CODESPLIT] def container ( account , container , head ) if head get_request ( address ( account + \"/\" + container ) , @token ) else head_request ( address ( account + \"/\" + container ) , @token ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "通过（名称、字符）替换表情 [CODESPLIT] def replace_emoji_with_images ( string ) return string unless string html ||= string . dup html = replace_name_with_images ( html ) html = replace_unicode_with_images ( html . to_str ) return html end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "通过（名称）替换表情 [CODESPLIT] def replace_name_with_images ( string ) unless string && string . match ( names_regex ) return string end string . to_str . gsub ( names_regex ) do | match | if names . include? ( $1 ) %Q{<img class=\"emoji\" src=\"//#{ image_url_for_name($1) }\" />} else match end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "通过（字符）替换表情 [CODESPLIT] def replace_unicode_with_images ( string ) unless string && string . match ( unicodes_regex ) return string end html ||= string . dup html . gsub! ( unicodes_regex ) do | unicode | %Q{<img class=\"emoji\" src=\"//#{ image_url_for_unicode(unicode) }\" />} end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "通过（名称）合成图片地址 [CODESPLIT] def image_url_for_name ( name ) image_url = \"#{asset_host}#{ File.join(asset_path, name) }.png\" if image_url . present? if asset_size . present? && asset_size . in? ( sizes ) image_url = [ image_url , asset_size ] . join ( asset_delimiter ) end end return image_url end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Last parameter in array can be a hash of objects It is implemented this way ( instead of ( * models instrument : true )) because when passing in Sequel models ruby will invoke the . to_hash on them causing a load when trying to restructure the args [CODESPLIT] def finalize! ( * models_and_opts ) models , instrument = if models_and_opts . last . kind_of? ( :: Hash ) ins = models_and_opts . last . fetch ( :instrument ) do true end [ models_and_opts [ 0 .. - 2 ] , ins ] else [ models_and_opts , true ] end if instrument ActiveSupport :: Notifications . instrument 'praxis.mapper.finalize' do _finalize! ( models ) end else _finalize! ( models ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "don t doc . never ever use yourself! FIXME : make private and fix specs that break? [CODESPLIT] def finalize_model! ( model , query = nil ) staged_queries = @staged [ model ] . delete ( :_queries ) || [ ] staged_keys = @staged [ model ] . keys non_identities = staged_keys - model . identities results = Set . new return results if @staged [ model ] . all? { | ( _key , values ) | values . empty? } if query . nil? query_class = @connection_manager . repository ( model . repository_name ) [ :query ] query = query_class . new ( self , model ) end # Apply any relevant blocks passed to track in the original queries staged_queries . each do | staged_query | staged_query . track . each do | ( association_name , block ) | next unless block spec = staged_query . model . associations [ association_name ] if spec [ :model ] == model query . instance_eval ( block ) if ( spec [ :type ] == :many_to_one || spec [ :type ] == :array_to_many ) && query . where file , line = block . source_location trace = [ \"#{file}:#{line}\" ] | caller raise RuntimeError , \"Error finalizing model #{model.name} for association #{association_name.inspect} -- using a where clause when tracking associations of type #{spec[:type].inspect} is not supported\" , trace end end end end # process non-unique staged keys #   select identity (any one should do) for those keys and stage blindly #   load and add records. if non_identities . any? to_stage = Hash . new do | hash , identity | hash [ identity ] = Set . new end non_identities . each do | key | values = @staged [ model ] . delete ( key ) rows = query . multi_get ( key , values , select : model . identities , raw : true ) rows . each do | row | model . identities . each do | identity | if identity . kind_of? Array to_stage [ identity ] << row . values_at ( identity ) else to_stage [ identity ] << row [ identity ] end end end end self . stage ( model , to_stage ) end model . identities . each do | identity_name | values = self . get_staged ( model , identity_name ) next if values . empty? query . where = nil # clear out any where clause from non-identity records = query . multi_get ( identity_name , values ) # TODO: refactor this to better-hide queries? self . queries [ model ] . add ( query ) results . merge ( add_records ( records ) ) # add nil records for records that were not found by the multi_get missing_keys = self . get_staged ( model , identity_name ) missing_keys . each do | missing_key | @row_keys [ model ] [ identity_name ] [ missing_key ] = nil get_staged ( model , identity_name ) . delete ( missing_key ) end end query . freeze # TODO: check whether really really did get all the records we should have.... results . to_a end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return the record provided ( if added to the identity map ) or return the corresponding record if it was already present [CODESPLIT] def add_record ( record ) model = record . class record . identities . each do | identity , key | # FIXME: Should we be overwriting (possibly) a \"nil\" value from before? #        (due to that row not being found by a previous query) #        (That'd be odd since that means we tried to load that same identity) if ( existing = @row_keys [ model ] [ identity ] [ key ] ) # FIXME: should merge record into existing to add any additional fields return existing end get_staged ( model , identity ) . delete ( key ) @row_keys [ model ] [ identity ] [ key ] = record end @secondary_indexes [ model ] . each do | key , indexed_values | val = if key . kind_of? Array key . collect { | k | record . send ( k ) } else record . send ( key ) end indexed_values [ val ] << record end record . identity_map = self @rows [ model ] << record record end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Turns all urls into clickable links . If a block is given each url is yielded and the result is used as the link text . [CODESPLIT] def urls ( text ) text . gsub ( @regex [ :protocol ] ) do scheme , href = $1 , $& punctuation = [ ] if auto_linked? ( $` , $' ) # do not change string; URL is already linked href else # don't include trailing punctuation character as part of the URL while href . sub! ( / #{ @regex [ :word_pattern ] } \\/ / , '' ) punctuation . push $& if opening = @regex [ :brackets ] [ punctuation . last ] and href . scan ( opening ) . size > href . scan ( punctuation . last ) . size href << punctuation . pop break end end link_text = block_given? ? yield ( href ) : href href = '//' + href unless scheme \"<a href='#{href}' target='_blank'>#{link_text}</a>\" + punctuation . reverse . join ( '' ) end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Turns all email addresses into clickable links . If a block is given each email is yielded and the result is used as the link text . [CODESPLIT] def email_addresses ( text ) text . gsub ( @regex [ :mail ] ) do text = $& if auto_linked? ( $` , $' ) text else display_text = ( block_given? ) ? yield ( text ) : text # mail_to text, display_text \"<a href='mailto:#{text}'>#{display_text}</a>\" end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Specifies a new pluralization rule and its replacement . The rule can either be a string or a regular expression . The replacement should always be a string that may include references to the matched data from the rule . [CODESPLIT] def plural ( rule , replacement ) @uncountables . delete ( rule ) if rule . is_a? ( String ) @uncountables . delete ( replacement ) @plurals . insert ( 0 , [ rule , replacement ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Specifies a new singularization rule and its replacement . The rule can either be a string or a regular expression . The replacement should always be a string that may include references to the matched data from the rule . [CODESPLIT] def singular ( rule , replacement ) @uncountables . delete ( rule ) if rule . is_a? ( String ) @uncountables . delete ( replacement ) @singulars . insert ( 0 , [ rule , replacement ] ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Specifies a new irregular that applies to both pluralization and singularization at the same time . This can only be used for strings not regular expressions . You simply pass the irregular in singular and plural form . [CODESPLIT] def irregular ( singular , plural ) @uncountables . delete ( singular ) @uncountables . delete ( plural ) if singular [ 0 , 1 ] . upcase == plural [ 0 , 1 ] . upcase plural ( Regexp . new ( \"(#{singular[0,1]})#{singular[1..-1]}$\" , \"i\" ) , '\\1' + plural [ 1 .. - 1 ] ) singular ( Regexp . new ( \"(#{plural[0,1]})#{plural[1..-1]}$\" , \"i\" ) , '\\1' + singular [ 1 .. - 1 ] ) else plural ( Regexp . new ( \"#{singular[0,1].upcase}(?i)#{singular[1..-1]}$\" ) , plural [ 0 , 1 ] . upcase + plural [ 1 .. - 1 ] ) plural ( Regexp . new ( \"#{singular[0,1].downcase}(?i)#{singular[1..-1]}$\" ) , plural [ 0 , 1 ] . downcase + plural [ 1 .. - 1 ] ) singular ( Regexp . new ( \"#{plural[0,1].upcase}(?i)#{plural[1..-1]}$\" ) , singular [ 0 , 1 ] . upcase + singular [ 1 .. - 1 ] ) singular ( Regexp . new ( \"#{plural[0,1].downcase}(?i)#{plural[1..-1]}$\" ) , singular [ 0 , 1 ] . downcase + singular [ 1 .. - 1 ] ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "run the action if valid and return true if successful [CODESPLIT] def execute raise errors . to_sentences unless valid? # default failing command result = false # protect command from recursion mutex = Mutagem :: Mutex . new ( 'revenc.lck' ) lock_successful = mutex . execute do result = system_cmd ( cmd ) end raise \"action failed, lock file present\" unless lock_successful result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "= begin def my_set_render_template ( tpl_view tpl_layout ) @optimacms_tpl = tpl_view @optimacms_layout = tpl_layout end [CODESPLIT] def renderActionInOtherController ( controller , action , params , tpl_view = nil , tpl_layout = nil ) # include render into controller class if current_cms_admin_user controller . send 'include' , Optimacms :: Renderer :: AdminPageRenderer controller . send 'renderer_admin_edit' end # c = controller . new c . params = params if current_cms_admin_user #if !controller.respond_to?(:render_base, true) if ! c . respond_to? ( :render_base , true ) controller . send :alias_method , :render_base , :render controller . send :define_method , \"render\" do | options = nil , extra_options = { } , & block | if current_cms_admin_user && @pagedata render_with_edit ( options , extra_options , block ) else render_base ( options , extra_options , block ) end end end end #c.process_action(action, request) #c.dispatch(action, request) #c.send 'index_page' c . request = request #c.request.path_parameters = params.with_indifferent_access c . request . format = params [ :format ] || 'html' c . action_name = action c . response = ActionDispatch :: Response . new c . send 'my_set_render' c . send 'optimacms_set_pagedata' , @pagedata c . send 'my_set_render_template' , tpl_view , tpl_layout c . send 'my_set_meta' , @pagedata . meta #renderer_admin_edit #c.process_action(action) c . dispatch ( action , request , c . response ) #c.process_action(action, tpl_filename) #app = \"NewsController\".constantize.action(action) #app.process params # result #c c . response . body #app.response.body end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : disable Metrics / MethodLength [CODESPLIT] def adjust_values ( act , payload ) payload . each do | key , value | case value when Hash act [ :tags ] . merge! ( value . select { | _ , v | v . is_a? ( String ) } ) when Numeric , Integer act [ :values ] [ key . to_sym ] = value . to_f when String , TrueClass , FalseClass act [ :values ] [ key . to_sym ] = value when Symbol act [ :values ] [ key . to_sym ] = value . to_s else next end end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "rubocop : enable Metrics / MethodLength [CODESPLIT] def organize_event ( event ) act = { values : { duration : event . duration } , tags : { name : event . name } } adjust_values ( act , event . payload ) act end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Output the results based on the requested output format [CODESPLIT] def output opts = options if opts . format FileUtils . mkdir_p opts . output_dir formatted_output end @results . clear end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Run httperf from low_rate to high_rate stepping by rate_step [CODESPLIT] def run while @jobs . length > 0 do # do a warm up run first with the highest connection rate @current_job = @jobs . pop @current_rate = @current_job . high_rate . to_i httperf true ( @current_job . low_rate . to_i .. @current_job . high_rate . to_i ) . step ( @current_job . rate_step . to_i ) do | rate | @current_rate = rate httperf end output end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Detection [CODESPLIT] def file? ( filename ) return unless filename File . exist? File . join ( @library . source_path , filename . split ( '/' ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Authenticate via keystone unless a token and tenant are defined then a unscoped token is returned with all associated data and stored in the [CODESPLIT] def authenticate ( username , password , tenant = nil ) data = { \"auth\" => { \"passwordCredentials\" => { \"username\" => username , \"password\" => password } } } unless tenant . nil? data [ \"auth\" ] [ \"tenantName\" ] = tenant end @data = post_request ( address ( \"/tokens\" ) , data , @token ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Scope token provides two ways to call it : scope_token ( tenantName ) = > Just using the current token and a tenantName it scopes in the token . Token stays the same . scope_token ( username password tenantName ) = > This uses the username and password to reauthenticate with a tenant . The token changes . [CODESPLIT] def scope_token ( para1 , para2 = nil , para3 = nil ) if ( para2 . nil? ) data = { \"auth\" => { \"tenantName\" => para1 , \"token\" => { \"id\" => token ( ) } } } @data = post_request ( address ( \"/tokens\" ) , data , token ( ) ) else authenticate ( para1 , para2 , token ( ) , para3 ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add a service to the keystone services directory [CODESPLIT] def add_to_services ( name , type , description ) data = { 'OS-KSADM:service' => { 'name' => name , 'type' => type , 'description' => description } } return post_request ( address ( \"/OS-KSADM/services\" ) , data , token ( ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Add an endpoint list [CODESPLIT] def add_endpoint ( region , service_id , publicurl , adminurl , internalurl ) data = { 'endpoint' => { 'region' => region , 'service_id' => service_id , 'publicurl' => publicurl , 'adminurl' => adminurl , 'internalurl' => internalurl } } return post_request ( address ( \"/endpoints\" ) , data , token ( ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Get the endpoint list [CODESPLIT] def get_endpoints ( token = nil ) if token . nil? return get_request ( address ( \"/endpoints\" ) , token ( ) ) else return get_request ( address ( \"/tokens/#{token}/endpoints\" ) , token ( ) ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Disables an instance method . [CODESPLIT] def disable_method ( method_name , message = nil ) disabled_methods [ method_name ] ||= DisabledMethod . new ( self , method_name , message ) disabled_methods [ method_name ] . disable! end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Returns a Proc that acts as a replacement for the disabled method . [CODESPLIT] def to_proc disabled_method = self # This proc will be evaluated with \"self\" set to the original object. Proc . new do | * args , & block | disabled_method . execute ( self , args , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "The replacement for the original method . It will raise a NoMethodError if the method is disabled . Otherwise it will execute the original method . [CODESPLIT] def execute ( object , * args , & block ) if disabled? raise NoMethodError , message else object . send ( aliased_name , args , block ) end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Replaces the original implementation of the method with an implementation that allows disabling . [CODESPLIT] def alias_method! klass . send ( :define_method , replacement_name , self ) klass . send ( :alias_method , aliased_name , method_name ) klass . send ( :alias_method , method_name , replacement_name ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "calculate public key from secret [CODESPLIT] def secret_to_public ( secret , form = :byte ) publickey = p_secret_to_public ( change_argument_format ( secret , form ) ) return change_result_format ( publickey , form ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "convert int to byte - string ( littleEndian ) num : unsigned number to convert to bytes length : byte length [CODESPLIT] def int_to_bytes ( num , length ) raise ArgumentError , \"num :\" + num . to_s if num < 0 raise ArgumentError , \"length :\" + length . to_s if length < 0 hex_str = num . to_s ( 16 ) hex_str = hex_str . rjust ( length 2 , \"0\" ) return hexstr_to_bytes ( hex_str ) . reverse [ 0 , length ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "region calculate mod calculate base ** exponent % modulus [CODESPLIT] def pow_mod ( base , exponent , modulus ) raise ArgumentError if exponent < 0 || modulus < 0 # result of Nmod1 is always 0 return 0 if modulus . equal? 1 result = 1 base = base % modulus while exponent > 0 result = result base % modulus if ( exponent % 2 ) . equal? 1 exponent = exponent >> 1 base = base base % modulus end return result end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "region calculate point of ed25519 curve Points are represented as array [ X Y Z T ] of extended coordinates with x = X / Z y = Y / Z x * y = T / Z [CODESPLIT] def point_add ( pa , pb ) _A = ( pa [ 1 ] - pa [ 0 ] ) * ( pb [ 1 ] - pb [ 0 ] ) % @@p _B = ( pa [ 1 ] + pa [ 0 ] ) * ( pb [ 1 ] + pb [ 0 ] ) % @@p _C = 2 * pa [ 3 ] * pb [ 3 ] * @@d % @@p _D = 2 * pa [ 2 ] * pb [ 2 ] % @@p _E = _B - _A _F = _D - _C _G = _D + _C _H = _B + _A return [ _E _F , _G _H , _F _G , _E _H ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "Computes pointQ = s * pointA [CODESPLIT] def point_mul ( s , pa ) pq = [ 0 , 1 , 1 , 0 ] # Neutral element while s > 0 do pq = point_add ( pq , pa ) unless ( s & 1 ) . equal? 0 pa = point_add ( pa , pa ) s >>= 1 end return pq end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "return point A == point B [CODESPLIT] def point_equal ( pa , pb ) # x1 / z1 == x2 / z2  <==>  x1 * z2 == x2 * z1 return false if ( pa [ 0 ] * pb [ 2 ] - pb [ 0 ] * pa [ 2 ] ) % @@p != 0 return false if ( pa [ 1 ] * pb [ 2 ] - pb [ 1 ] * pa [ 2 ] ) % @@p != 0 return true end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "region point manipulation Compute corresponding x - coordinate with low bit corresponding to sign or return nil on failure [CODESPLIT] def recover_x ( y , sign ) return nil if y >= @@p # x2 means x^2 x2 = ( y y - 1 ) * modp_inv ( @@d y y + 1 ) # when x2==0 and sign!=0, these combination of arguments is illegal if x2 . equal? 0 then unless sign . equal? 0 then return nil else return 0 end end # Compute square root of x2 x = pow_mod ( x2 , ( ( @@p + 3 ) / 8 ) , @@p ) x = x * @@modp_sqrt_m1 % @@p unless ( ( x x - x2 ) % @@p ) . equal? 0 return nil unless ( ( x x - x2 ) % @@p ) . equal? 0 x = @@p - x unless ( x & 1 ) . equal? sign return x end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "compress element [ point ] of ed25519 curve [CODESPLIT] def point_compress ( p ) zinv = modp_inv ( p [ 2 ] ) x = p [ 0 ] * zinv % @@p y = p [ 1 ] * zinv % @@p # OR can be used to set the least significant bit of x to the most significant bit of y # because the most significant bit of \"y\" is always zero c = y | ( ( x & 1 ) << 255 ) return int_to_bytes ( y | ( ( x & 1 ) << 255 ) , 32 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "decompress point that is compressed into 32bytes [CODESPLIT] def point_decompress ( s ) # check argument raise ArgumentError , \"Invalid input length for decompression\" unless s . length . equal? 32 y = int_form_bytes ( s ) sign = y >> 255 y &= ( 1 << 255 ) - 1 x = recover_x ( y , sign ) if x . nil? then return nil else return [ x , y , 1 , x y % @@p ] end end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "region key manipulation hash512 ( secret ) = > HASH ( 512bit ) = > [ LH ( 256bit ) ] / [ RH ( 256bit ) ] = > LH - > ( set some bits ) - > a return ( a RH ) [CODESPLIT] def secret_expand ( secret ) raise \"Bad size of private key\" unless secret . length . equal? 32 h = hash512 ( secret ) a = int_form_bytes ( h [ 0 , 32 ] ) a &= ( 1 << 254 ) - 8 a |= ( 1 << 254 ) return [ a , h [ 32 , 32 ] ] end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "region sign and verify [ signature format ] | compressed data of _R | s | < - concatnate [CODESPLIT] def p_sign ( secret , message ) a , prefix = secret_expand ( secret ) _A = point_compress ( point_mul ( a , @@G ) ) r = hash512_modq ( prefix + message ) _R = point_mul ( r , @@G ) _Rs = point_compress ( _R ) h = hash512_modq ( _Rs + _A + message ) s = ( r + h * a ) % @@q return _Rs + int_to_bytes ( s , 32 ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "public_keyKey = aG a is generated form a secret [CODESPLIT] def p_secret_to_public ( secret ) expanded = secret_expand ( secret ) a = expanded . first return point_compress ( point_mul ( a , @@G ) ) end", "target": 1, "target_options": ["no_match", "match"]}
{"input": "get part by its name param [CODESPLIT] def part ( name ) parts . select { | p | p . name . downcase == name . to_s . downcase } . first end", "target": 1, "target_options": ["no_match", "match"]}
