Skip to content

The easiest and the cleanest way to add some configuration variables to any ruby project.

License

Notifications You must be signed in to change notification settings

kwi/awesome_conf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AwesomeConf

AwesomeConf is a really simple and powerful ruby gem built with performance in mind, it’s the easiest and the cleanest way to add some configuration variables to any ruby project.

It does almost nothing, it just give you the ability to create and use easily a configuration class for any of your ruby project.

It’s like an Hash but it’s not an Hash.

It’s like an OpenStruct but it’s not an OpenStruct, it’s faster.

It’s like a bird, but it’s not a bird.

AwesomeConf example

require 'awesome_conf'

ac = AwesomeConf.new(:key => 'value')
ac.key # => 'value'

Ok, nothing is magic here, it can be any easy ruby tricks returning the value of this hash, like using method_missing or using an OpenStruct. But this is not, it’s a real brand new method created dynamically returning a constant.

Why? For speed, and to be as faster as hash[:key] and two times faster than hash[‘key’] (at least using the classic ruby VM 1.8 and 1.9, with jRuby: hash is faster than everything !)

So to conclude, AwesomeConf is just an easy replacement of conf to conf.my_conf_variable without sacrificing performance. (benchmarks are available in the specs)

Other use cases:

AwesomeConf with YAML

AwesomeConf.new('path_to_a_yaml_file.yaml')

AwesomeConf and strict mode

ac = AwesomeConf.new({:key => 'value'})
ac.key # => 'value'
ac.something_not_set # => nil

# After enabling the strict mode:

ac.strict!
ac.something_not_set # Raise an exception

AwesomeConf with inheritance

class MyConfClass < AwesomeConf

  def initialize(an_hash)
    super(an_hash)
  end

  ... your_awesome_custom_methods ...

end

Copyright © 2010 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license

About

The easiest and the cleanest way to add some configuration variables to any ruby project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages