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

configlet

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configlet

  • 2.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Configlet

  • http://github.com/jbarnette/configlet

== Description

A stupid simple wrapper for environment variables.

This doesn't deserve to be released as a gem, but I'm using it in two different projects. Seriously, go find a real configuration library and use it instead.

== Examples

require "configlet"

# assuming...
ENV["THUNK_STATUS"]   = "crazy-awesome"
ENV["THUNK_FINISHED"] = "false"

# some bits of optional config
Configlet.prefix = :thunk
Configlet.default :token => "default-token"
Configlet.munge(:finished) { |k| "true" == k }

# grabbin' values
Configlet[:status]   # => "crazy-awesome"
Configlet[:finished] # => false
Configlet[:token]    # => "default-token"

There's also a block form, which is nice if you're setting a lot of defaults:

Configlet.config :thunk do
  default :token => "default-token"
  default :host  => "thunk.local"
end

Defaults can be lazy, too: Just use a lambda. The default will be resolved the first time its value is grabbed.

default :db => lambda { "db://whatever/#{Rails.env}" } # or...
default(:db) { "db://whatever/#{Rails.env}" }

Configlet is a module, so +include+ or +extend+ it wherever you want. It extends itself for your convenience.

== Transformation

Want something other than a string? You can munge any value:

default :url => "http://example.org"
munge(:url) { |v| URI.parse v }
Configlet[:url] # => #<URI::HTTP:0xdeadbeef URL:http://example.org>

In fact, there's a shortcut just for URLs. I haven't added any others 'cause I haven't needed to care:

url :url => "http://example.org"
Configlet[:url] # => #<URI::HTTP:0xcafebabe URL:http://example.org>

== Installation

$ gem install configlet

== License

Copyright 2010 John Barnette (code@jbarnette.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 17 Dec 2010

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