Git Product home page Git Product logo

lemme-pry's Introduction

lemme-pry

Start a pry-session with specific gems or a (remote) script preloaded.
For the idea behind this gem see this blogpost.

Usage

This gem allows you to get a pry-session with either...

  1. gems preloaded
  2. a script preloaded

pry-session with gems pre-loaded

This requires lemme-pry to be installed system-wide.

# to get the latest version of ActiveSupport
$ lemme-pry activesupport
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Using concurrent-ruby 1.0.5
Using i18n 0.8.1
Using minitest 5.10.1
Using thread_safe 0.3.6
Using coderay 1.1.1
Using method_source 0.8.2
Using slop 3.6.0
Using bundler 1.14.5
Using tzinfo 1.2.2
Using pry 0.10.4
Using activesupport 5.0.2
[2] pry(main)> 1.second
=> 1 second

Use a specific version:

# any version notation that is accepted in a Gemfile will work 
$ lemme-pry activesupport '~> 4.2'
...
[2] pry(main)>

Multiple gems:

$ lemme-pry activesupport '~> 4.2' redis
...
[2] pry(main)>

pry-session with script preloaded

Anything piped to lemme-pry will be evaluated before the pry-session starts:

$ echo '@a = 1' | lemme-pry
[1] pry(main)> @a
=> 1
# handy when sharing code with others:
$ curl https://gist.githubusercontent.com/eval/76955c57512c1e4ac01cdd913b76c92d/raw/bf714a15789eca3e968c3544f85b9b786b8eae8f/hello.rb | lemme-pry

# or via the gist command:
$ gist -r 76955c57512c1e4ac01cdd913b76c92d | lemme-pry

NOTE: curl-pipe-runtime is not without risk. A tool like vipe (npm variant) allows you to inspect the fetched script before handing it over to lemme-pry.

within a (Rails-)project

When the script needs to be evaluated within a project (i.e. use the gems of your project), make sure lemme-pry is part of your project.

A script for a Rails project would typically look like this:

# script.rb
require './config/environment' # load Rails-application
@user = User.first

Evaluate via:

cat script.rb | bundle exec lemme-pry
...
[1] pry(main)> @user
#<User id: 1, username: ...

Installation

System-wide

$ gem install lemme-pry

Within project

Add the following to Gemfile:

# Gemfile
gem 'lemme-pry', group: :development

Development

After checking out the repo, run bin/setup to install dependencies. Then run the tool via:

$ ruby -Ilib exe/lemme-pry activesupport

License

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

lemme-pry's People

Contributors

eval avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.