Git Product home page Git Product logo

gist-dep's Introduction

Description

gist-dep

A gem-like tool for managing small reusable code snippets in a project

Useful for small bits of functionality that are used repeatly in different projects and/or by different developers. Ruby monkey-patches, Javascript polyfills, common styles, etc are great examples.

Anytime you want to re-use code but the amount of code is so small it is silly to create a library gist-dep is your answer.

Installation

First you need a Ruby runtime up and running. You can use gist-dep in any language project. But gist-dep is itself written in Ruby and installed through Ruby’s gem system. So first install Ruby. I’m a fan of installing via rbenv but that may be too technical for some and a pre-built package may be best if you are not technically inclined. Just make sure it is a recent version of Ruby (2.0 or 1.9).

Next open up your command line tool and type:

gem install gist-dep

If you are running rbenv you may need to run the following afterwards:

rbenv rehash

Now you should be setup to use gist-dep.

Usage

Install a New Gist

When you only have one file on the gist:

%> gist-dep add 732081
Adding engine_mixin.rb from gist 732081

Saving the gist to a specific path:

%> gist-dep add --path app/assets/javascripts 795566
Adding placeholder.coffee from gist 795566 to app/assets/javascripts

Specifying a specific file in gist having more than one file:

%> gist-dep add --path app/models 519630/db_config.rb

If a gist has more than one non-doc file and you don’t specify which file it will prompt you to find out which one you want.

Renaming a file as you install it:

%> gist-dep add --path db/migrations/20130509000000_add_db_config.rb 519630/migration.rb

Updating a Gist

Update to the latest version of the gist:

%> gist-dep update 732081
Downloading latest engine_mixin.rb from gist 732081

If you have more than one file from a gist you can specify which one:

%> gist-dep update 519630/db_config.rb
Downloading latest db_config.rb from gist 519630

If you have more than one file from a gist and you don’t specify which file it update all files from that gist.

You can also update all gists by just not specifying any gist.

%> gist-dep update
Downloading latest engine_mixin.rb from gist 732081
Downloading latest db_config.rb from gist 519630

Removing a Gist

Basic removal:

%> gist-dep remove 732081
Removing engine_mixin.rb

Remove a specific file when you have more than one from a gist:

%> gist-dep remove 519630/db_config.rb

If you have more than one file from a gist and you don’t specify which file it will remove all from that gist.

Listing Gists

List all installed gists and their installed location:

%> gist-dep list
732081/engine_mixin.rb -> lib/engine_mixin.rb
519630/db_config.rb -> app/models/db_config.rb
519640/migration.rb -> db/migrations/20130509000000_add_db_config.rb

Seeing Changes

If you want to see the difference between your copy of a gist file and the gist.github.com version you can run a diff.

%> gist-dep diff 732081

If you have more than one file from the same gist you can specify a specific file:

%> gist-dep diff 519630/db_config.rb

If you don’t specify a specific file it will show a diff of all files on that gist that are installed in your project.

If you want to see a diff on all gists installed on your project you can simply run without any arguments.

%> gist-dep diff

By default the ‘diff’ program is used to show the differences. But you can specify an alternate program via the -d option:

%> gist-dep diff -d diffuse

Authenticated Access

Buy authenticating yourself with GitHub you gain three additional features:

  • Allows you to install your private gists

  • Allows you to push your changes back up to gist.github.com

  • The rate limiting functions are less severe ensuring gist-dep doesn’t encounter errors when accessing Gists. This is probably not a huge concern unless you are running the tests or doing a lot with gist-dep

To authenticate:

%> gist-dep login
Enter your username: eric1234
Enter your password: notmypassword
gist-dep is now authenticated

Your username/password will be used to get an OAuth token which will be stored at ~/.gist-dep.yml. This file will be set with 600 permissions so only your user can read/write. All future interaction with gist.github.com will be authenticated.

If you want to log GistDep out simply remove the ~/.gist-dep.yml file and remove the authorization from GitHub.

Uploading Gists

If you make updates to a gist and are authenticated you can push your changes to gist.github.com via:

%> gist-dep push 732081
Uploading engine_mixin.rb to 732081

If you aren’t the owner of the gist it will automatically fork the gist and push your changes to your fork. Future pushes will push to the same fork:

%> gist-dep push 294896
Uploading getHtml.coffee from 294896 to fork at 4063653

Configuration

The file ‘gist-dep.yml` is added to your project to manage the list of gists installed on your project. You can specify a different location for the config file the `-C` options (or `–config`):

%> gist-dep -C config/gist-dep.yml add 732081
Adding engine_mixing.rb from gist 732081

If you decide that you don’t want to use gist-dep anymore, simply remove the config file and you are back to managing your small code snippets manually.

Testing

The tests require a GitHub account since we do real interactions with the Gist API. Also this gets around rate limiting functions that would otherwise cause the tests to fail. Your credentials are set by providing the environment variables GITHUB_LOGIN and GITHUB_PASSWORD. To make this easier you can create a .env file in the root directory to have these values automatically given.

Also you should have gist-dep logged in since we use your real token login to do some of the tests. If you are not logged in these tests are skipped.

After that you can run an individual test with:

bundle exec ruby test/some_test.rb

If you want to run all unit tests:

rake test:unit

To run all integration tests:

rake test:integration

To run all tests:

rake test

Or just:

rake

The testing process will create a few authorizations in your GitHub account but will clean them up after. It will also create a Gist in your GitHub account but will also clean that up after.

Organizing your Gists

After a while you might build a decent list of code snippets you share between projects and developers. While Gist is great at managing a single gist it isn’t very good at organizing a collection of gists. For that I cannot recommend GistBox highly enough.

Credit & License

This software was developed by Eric Anderson (pixelwareinc.com). It is public domain software and you can use however you see fit as long as you USE AT YOUR OWN RISK.

gist-dep's People

Contributors

eric1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gist-dep's Issues

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Login not working

% gist-dep login
error: undefined method `oauthed?' for Octokit:Module

How does this work?

The readme uses gists as numbers, but on gist.github.com I cannot find these numbers anywhere.

It seems to be more like the github repository syntax now, e.g. https://gist.github.com/pboling/fcacde21424e81b5bf2f.

Does this project still work?

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.