Sha256: ae49b5565efa7d46a6b5dacdaab70599480293a5ad45c068c55ddee6bdab00e0

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

# GemConfig

[![Gem Version](https://badge.fury.io/rb/gem_config.png)](http://badge.fury.io/rb/gem_config)
[![Build Status](https://secure.travis-ci.org/krautcomputing/gem_config.png)](http://travis-ci.org/krautcomputing/gem_config)
[![Dependency Status](https://gemnasium.com/krautcomputing/gem_config.png)](https://gemnasium.com/krautcomputing/gem_config)
[![Code Climate](https://codeclimate.com/github/krautcomputing/gem_config.png)](https://codeclimate.com/github/krautcomputing/gem_config)

A nifty way to make your gem configurable.

## Usage

### As a gem author

Include the gem and add configuration options like this:

```ruby
# awesomeness.gemspec
Gem::Specification.new do |gem|
  ...
  gem.add_runtime_dependency 'gem_config'
end

# lib/awesomeness.rb
module Awesomeness
  include GemConfig::Base

  with_configuration do
    has :api_key, classes: String
    has :format, values: [:json, :xml], default: :json
    has :region, values: ['us-west', 'us-east', 'eu'], default: 'us-west'
  end
end
```

Access the configuration values in the gem's code like this:

```ruby
Awesomeness.configuration.api_key # Whatever the user set
```

### As a gem user

Include and configure a gem like this:

```ruby
# Gemfile
gem 'awesomeness'

# config/initializers/awesomeness.rb
Awesomeness.configure do |config|
  config.api_key = 'foobarbaz'
  config.format  = :xml
  config.region  = 'eu'
end
# or
Awesomeness.configuration.api_key = 'foobarbaz'
```

Of course configuration values are checked against the allowed `classes` and `values`, and the `default` is used if no value is provided.

## Contributing

1. Fork it
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 new Pull Request

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gem_config-0.2.4 README.md
gem_config-0.2.3 README.md
gem_config-0.2.2 README.md