Giter Site home page Giter Site logo

set_man's Introduction

#SetMan Simple settings manager for your application.

##Requirements Rails 3 only.

##Install Add to your gemfile

gem 'set_man'

after this execute in console:

rails g set_man [ModelName]

##Overview

For enable SetMan for model, you can add call settings.

class Options < ActiveRecord::Base

  settings

end

For getting option, you can use get_option:

Options.get_option :site_name #=> "Site Name"

or shorten variant:

Options.get :site_name #=> "Site Name"

For setting option, you can use set_option:

Options.set_option :site_name, "New name" #=> "New Name"

or shorten variant:

Options.set :site_name, "New Name" #=> "New Name"

Methods set_option and set can given :to parameter:

Options.set_option :site_name, :to => "New Name" #=> "New Name"
Options.set :site_name, :to => "New Name" #=> "New Name"

If given second argument, and :to, set_option will use second argument as new value:

Options.set_option :site_name, "New Name", :to => "Not New Name" #=> "New Name"

If option doesn't exists, then option will been created:

Options.set_option :not_existing_option, "Some value" #=> "Some value"

For deleting option, you can use del_option:

Options.del_option :site_name #=> "New Name"

or shorten variant:

Options.del :site_name #=> "New Name"

You can use methods with names of options for accessing:

Options.site_name #=> "Site Name"
Options.site_name = "New Name" #=> "Site Name"
Options.site_name? #=> true
Options.site_name! #=> "Site Name"

Postfix ? using for test of existing option. Postfix ! using for deleting option.

This is method not override default methods of ActiveRecord::Base methods and other. Example:

Options.columns_hash #=> columns list of table

If you need returning ActiveRecord::Base object, instead value of option, you can use :as_object => true:

Options.get_option :site_name, :as_object => true #=> #<Options ...>

This work for short names too:

Options.site_name :as_object => true #=> #<Options ...>

Multiple options

You can work with multiple options:

Options.get_options [:site_name, :site_description] #=> { "site_name" => "Site Name", "site_description" => "Site description" }
Options.set_options { :site_name => "New Site Name", :per_page => 20 } #=> { "site_name" => "New Site Name", :per_page => 20 }
Options.del_options [:site_name, :per_page] #=> { "site_name" => "New Site Name", "per_page" => 20 }

If given :as_object => true, returning array of objects, instead hash of values.

get_options and del_options return only existing options.

Ideas for next

  • Support of cache;
  • Default options;
  • Options group;
  • Callbacks, validations and own types.

Copyright (c) 2011 Alexey Plutalov, released under the MIT license

set_man's People

Contributors

demiazz avatar

Watchers

 avatar James Cloos avatar  avatar

set_man's Issues

Bug with default

Какие-то сложности с default. Требуется более тщательная проверка. В частности SQLite ругается на не уникальность поля, при default. Это настораживает.

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.