Simple Ruby configuration DSL
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
.gitignore
README.rdoc
Rakefile

README.rdoc

Kung-Figure

github.com/niquola/kung_figure

DESCRIPTION

Simple RUBY configuration DSL

INSTALL:

sudo gem install kung_figure

or for rails in config/environment.rb

config.gem 'kung_figure'

then

sudo rake gems:install

USAGE

Example:

module MyModule
  include KungFigure
  class Config < KungFigure::Base
    define_prop :prop1,'default1'
    define_prop :prop2, 2

    class NestedConfig < KungFigure::Base
      define_prop :prop3,'prop3'

      class NestedNestedConfig < KungFigure::Base
        define_prop :prop4,'prop4'
      end
    end
  end
end

This will mixin methods configure, config, load_config into MyModule:

MyModule.configure do
  prop1 'new value'
  nested_config do
     prop3 'new value'
  end
end

and accessors for configs:

MyModule.config.prop1
MyModule.config.nested_config.prop1

You can also include KungFigure into nested in module classes and declare Config class (subclassing KungFigure::Base) to get similar result:

module MyModule
  include KungFigure
  class Config < KungFigure::Base
    define_prop :prop1,'default1'
  end
  #somewhere in another file
  class WorkHorse
    include KungFigure
    class Config < KungFigure::Base
      define_prop :my_config,'default'
    end

    def meth
       #here we can use config inside instance
       config.my_config
    end
  end
end

Then your can access configuration with:

MyModule::WorkHorse.config or MyModule.config.work_horse

Or inside instances of WorkHorse as config method.

CHANGE LOG

  • 0.0.2 add MyModule.clear_config! (clear configs for all nested configs) and MyModule.clear_config (clear concrete configs) and KungFigure.clear_all_configs methods

  • 0.0.3 fix bug with boolean configs

TODO

  • add another configuration style

    Mod.confugure do |m|
       m.param 'value'
       m.nested_config |nc|
         nc.param1 'value2'
       end
    end

MORE

For more info see tests and source code :)

LICENSE:

(The MIT License)

Copyright © 2010 niquola

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.