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

duffel

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duffel

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Duffel

Fetch your environment variables. Raise errors or set defaults when a variable does not exist.

Installation

Add this line to your application's Gemfile:

gem 'duffel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install duffel

Usage

Duffel is a simple gem for reading things out of your environment.

You have something in your environment named SUPER_SECRET_PASSWORD? No problem. To get it out, just do the following:

Duffel.super_secret_password

Simple, right? But why add a layer of abstraction here? Well, there are a few reasons:

Most people get their environment variables like so: ENV['SUPER_SECRET_PASSWORD']. This will return nil if the variable is not found. Duffel will return a KeyError, so you are told about missing things.

But I don't want it to raise an exception!

That's fine too, you can specify a fallback for Duffel in case something isn't found. Example:

Duffel.super_secret_password(fallback: 'another-password')

What if I want to just return nil if it's not found?

No problem, we can set our fallback to nil:

Duffel.super_secret_password(fallback: nil)

What about other settings I might have?

I actually started writing this because I noticed was using a combination of ENV['SOME_VARIABLE_NAME_HERE'] and Settings.some_method_name. I wanted to just use the Settings.method_name pattern everywhere, so I wrote Duffel.

So while Duffel by default gets things out of your environment, you can use it as a general purpose settings drawer.

Let's say you wanted to actually have a constant called Settings but still take advantage of Duffel. You could do something like this:

class Settings < Duffel
  def self.some_other_awesome_setting
    'awesome setting return value'
  end
end

Calling Settings.env_variable_name will still return you your environment variable, should it exist.

Duffel is a stupid name

I know.

Why did you do it this way and not [obviously better way]?

Because I probably don't know the obviously better way. Feel free to submit a pull request or open an issue and I'll look into it!

Contributing

  1. Fork it ( https://github.com/ericroberts/duffel/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

FAQs

Package last updated on 11 Jul 2014

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