GithubHelp home page GithubHelp logo

mpapis / acts_as_configurable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rpheath/acts_as_configurable

2.0 1.0 1.0 90 KB

Rails plugin: rewriten version of plugin, settings are not writen into code, You have to write them down into config file - this helps to prevent using of wrong keys.

Home Page: http://niczsoft.com/2010/03/rails-acts_as_configurable-file-config/

License: MIT License

Ruby 100.00%

acts_as_configurable's Introduction

ActsAsConfigurable

!!! This is an fork of the original, code was completly rewritten, it works differently, read bellow for more informations !!!

Rails plugin that adds dynamic (non-database) configuration settings to any class (also models & controlers).

Installation

In rails application directory call:


script/plugin install [email protected]:mpapis/acts_as_configurable.git

Examples

Setup file:


default:
  :setting1: 1st
Book:
  :setting1: 2nd
settings:
  :setting1: 3rd
allow_comments: false

Example usages:


class User < ActiveRecord::Base
  acts_as_configurable  
end
puts "#{User.configuration[:setting1]}"
puts "#{User.new.configuration[:setting1]}"
class Book < ActiveRecord::Base
  acts_as_configurable
end
puts "#{Book.configuration[:setting1]}"
class Comment < ActiveRecord::Base
  acts_as_configurable :defult => :settings
end
puts "#{Comment.configuration[:setting1]}"
class Address < ActiveRecord::Base
  acts_as_configurable :field=>allow_comments
end
puts "#{Address.allow_comments}"
class Post < ActiveRecord::Base
  acts_as_configurable :conf, :for => :settings
  acts_as_configurable :conf_book, :for => Book
end
puts "#{Post.conf[:setting1]}"
puts "#{Post.new.conf_book[:setting1]}"

Default settings for :default, :name, :for, :default can be overwritten using:

ActsAsConfigurable::Configuration.default_method_name - set new default for name, if it is not set then 'configuration' is used
ActsAsConfigurable::Configuration.default_klass_name - set new default for 'for', if not set It tryes to use class name, but if not available 'default' will be used
ActsAsConfigurable::Configuration.default_key_name - another default definition, normally 'default' is good

All options can be specified as strings or symbols, additionally :for can also work with Class

Dependencies

This plugin mixes directly into Object, so there’s no dependency on another library. Any class can act as configurable.

Actually, ActiveSupport is required (thanks to cattr_accessor), but since this is a
plugin for a Rails application, there shouldn’t be any issues there.

Credits

Chris Scharf is the original author of this “on-the-fly” configuration.
His original implementation was intended for application wide configuration settings. You can find
his post about it here.

Ryan Heath is the author of original plugin.

With my version you can have the convenience of storing configuration in yaml file – you do not have to change code to change configuration.

© 2010 Michal Papis, Ryan Heath and Chris Scharf, released under the MIT license

acts_as_configurable's People

Contributors

mpapis avatar rpheath avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.