Code Monkey home page Code Monkey logo

simple_configuration's Introduction

SimpleConfiguration

SimpleConfiguration lets you write code that looks like configuration files, but keeps the dynamism that Ruby offers.

Why?

I work on a number of applications that require configuration that can't be expressed by simple values in the database or JSON file.

While the dynamism of the configuration makes it doubtful whether it's still a configuration or it should be juts written as plain Ruby code, I decided to write this simple library that makes these files look like configration files. I personally find it more conscise and easier to read than standard Ruby methods.

When should you use it? When your classes require a lot of small methods with simple behaviour. You can check examples/ to see how I use it.

Why not to use constants instead? Good question, I think they're good for static values, not so much for storing functions.

Installation

Add this line to your application's Gemfile:

gem 'simple_configuration'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_configuration

Usage

Check examples/ to see how you can use this gem.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Contribution is not only done by writing code!

If you find some problem with the gem and open an issue, if you mention it on your blog or tell your friend about it, you contribute to this gem's popularity.

Despite just a few commits, this gem is more or less complete. Having said that, if you find some issue, or have an idea on how to improve it, I'll be happy to talk to you!

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SimpleConfiguration project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

simple_configuration's People

Contributors

arnvald avatar

Stargazers

 avatar

Watchers

 avatar  avatar

simple_configuration's Issues

why not nil?

MISSING_VALUE = '__missing_value__'

just a guess

The reason is -- nil is a valid value that someone might want to set for a configuration attribute. If we tested for nil, we would not be able to tell these two scenarios apart:

MyApp.configure do
  app_id nil # expectation: assigns nil
  app_id     # expectation: returns current value
end

That blank object stored in MISSING_VALUE is only ever going to be equal to itself, so this way we can be certain that nobody is going to pass it into our method and cause an unintended read instead of a write.

fyi: my answer is copied elsewhere :D

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.