Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insert_after

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insert_after

  • 0.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Insert_after Gem Version

Inserts a line into a file after a line matching a regular expression. String comparisons are case-insensitive. Works on very large files because it reads the file line by line instead of reading the entire file into memory.

Can be used on the command line or in a Ruby program.

Command-line Installation

$ gem install insert_after

Installation For Use In a Ruby Program

Either add this line to your application’s Gemfile:

gem 'insert_after'

... or add the following to your application’s .gemspec:

spec.add_dependency 'insert_after'

And then execute:

$ bundle

Command-line Usage

# Inserts 'Inserted 1' after the first line containing 'line' into demo/my_file.txt:
$ insert_after line 'Inserted 1' demo/my_file.txt

# Inserts an empty line after the first line containing 'line 1' into demo/my_file.txt:
$ insert_after 'line 1' '' demo/my_file.txt

# Inserts 'Inserted 2' after the first line starting with 'line 2' into demo/my_file.txt:
$ insert_after '^line 2' 'Inserted 2' demo/my_file.txt

# Inserts 'Inserted 3' after the first line containing an 'e' followed by a '2' into demo/my_file.txt:
$ insert_after 'e.*2' 'Inserted 3' demo/my_file.txt

Ruby Program Usage

The demo/demo.rb program is an example of how to use insert_after in a Ruby program:

require 'insert_after'

InsertAfer.insert_after  'line 2', 'New line',               'my_file.txt'
InsertAfter.insert_after 'line',   'Another line from Ruby', 'my_file.txt', all: true

Development

After checking out this git repository, install dependencies by typing:

$ bin/setup

You should do the above before running Visual Studio Code.

Run the Tests

$ bundle exec rspec

Interactive Session

The following will allow you to experiment:

$ bin/console

Local Installation

To install this gem onto your local machine, type:

$ bundle exec rake install

To Release A New Version

To create a git tag for the new version, push git commits and tags, and push the new version of the gem to https://rubygems.org, type:

$ bundle exec rake release

Contributing

Bug reports and pull requests are welcome at https://github.com/mslinn/insert_after.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 10 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc