GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - krbullock/configurable: Make your Ruby class or app configurable with a simple mixin.

BranchesTags
Open more actions menu

Latest commit

 

History

66 Commits
66 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
test
test
 
 
.autotest
.autotest
 
 
.hgignore
.hgignore
 
 
.hgtags
.hgtags
 
 
COPYING.txt
COPYING.txt
 
 
History.txt
History.txt
 
 
Manifest.txt
Manifest.txt
 
 
README.txt
README.txt
 
 
Rakefile
Rakefile
 
 

Repository files navigation

= configurable

* http://bitbucket.org/krbullock/configurable

== DESCRIPTION:

Lets you make your Ruby class configurable with a simple mixin.

== FEATURES/PROBLEMS:

* Generic mixin that you can use in any Ruby class (or application).

* Separates handling configuration of a class from its implementation.

* Supports nested settings.

* Rejects configuration keys outside those you specify.

* Supports setting defaults on a class which can then be modified for
  each instance of the class.

* Settings are stored in Structs (well, actually a subclass of Struct),
  so they can be accessed via normal methods calls, or by Symbol or
  String keys.

* Settings (even nested settings) can be serialized to a hash with
  string keys, which means you can also trivially serialize to YAML (or
  JSON).

* Settings (even nested settings) can be loaded from a hash, which means
  you can also trivially deserialize from YAML (and remember, YAML is a
  superset of JSON).

* Plays nicely with the Singleton module.

* Can safely store other kinds of structs as opaque config values. They
  won't get automatically deep-copied.

* Doesn't yet support independent configs for classes and their subclasses.

== SYNOPSIS:

 require 'configurable'
 class Doodad
   include Configurable

   # Declare the allowed options and their default values
   configurable_options :foo => 'default',
     :bar => {:quux => 42, :wibble => nil},
     :baz => nil
 end

 Doodad::Config              # => a ConfigStruct::Struct
 Doodad::Config::Bar         # => another ConfigStruct::Struct

 Doodad::Config.defaults     # => #<struct Doodad::Config
                             #     bar=#<struct Doodad::Config::Bar
                             #          quux=42, wibble=nil>,
                             #     baz=nil,
                             #     foo="default">

 Doodad.config               # => a (deep) copy of Doodad::Config.defaults,
                             #    ready for use

 Doodad.config.replace(      # replaces config with passed values
   :foo => 'mine',
   :bar => {:quux => 9})

 Doodad.config.update(       # loads config from a YAML file
   YAML.load('config.yml'))

See the documentation on Configurable for an overview and links to more
specifics.

=== Using with Rails

If you want to make a Rails class configurable, you'll need some special
mojo to reconfigure the class when it gets reloaded in development mode.
You can do this with Rails.application.config.to_prepare. For example,
to have your class configuration reloaded from a YAML file, create an
initializer like so:

 Rails.application.config.to_prepare do
   begin
     Doodad.config.update(
       YAML.load_file(File.join(Rails.root, 'config', 'doodad.yml')) || {})
   rescue Errno::ENOENT
     # handle missing config file
   end
 end

== REQUIREMENTS:

* Ruby

== INSTALL:

 $ gem install ruby-configurable

== DEVELOPERS:

After checking out the source, run:

 $ rake newb

This task will install any missing dependencies, run the tests/specs,
and generate the RDoc.

== LICENSE:

(GNU General Public License v2.0)

Copyright (C) 2010 Kevin R. Bullock

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

About

Make your Ruby class or app configurable with a simple mixin.

bitbucket.org/krbullock/configurable

Resources

Readme
GPL-2.0 license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.