README.md in o-2.0.2 vs README.md in o-2.0.3

- old
+ new

@@ -1,40 +1,41 @@ -O, a configuration libraray for Ruby +O, a configuration gem for Ruby ==================================== **Homepage**: [https://github.com/GutenYe/o](https://github.com/GutenYe/o) <br/> **Author**: Guten <br/> **License**: MIT-LICENSE <br/> **Documentation**: [http://rubydoc.info/gems/o/frames](http://rubydoc.info/gems/o/frames) <br/> **Issue Tracker**: [https://github.com/GutenYe/o/issues](https://github.com/GutenYe/o/issues) <br/> -then name `o` comes from option/setting, short and handy, eh-ah~ +The name `o` comes from option/setting, short and handy, eh-ah~ Features -------- -* support variable, computed attribute -* DSL syntax in pure ruby -* tree way to do configration. -* hash compatibility +* Variable and computed attribute support +* Pure Ruby DSL syntax +* Multiple configuration levels including system, user, and command-line. +* Hash compatibility Introduction ------------- -do configuration at three levels: system, user, cmdline +The three levels of configuration include system, user, and cmdline: - lib/guten/rc.rb # system level + APP/lib/guten/rc.rb # system level ~/.gutenrc # user level $ guten --list or ENV[GEMFILE]=x guten # cmdline level - + module Guten - Rc = O.require("guten/rc") + O.require("~/.gutenrc") + Rc = O.require("guten/rc") + O.require("~/.gutenrc") # require use $: Rc.list = true or Rc.gemfile = ENV[GEMFILE] # from cmdline. end + a constant works very well in many places, but you are free to use any variable. -### a completed example ### +### An example ### Rc = O do host "localhost" port 8080 mail.stmp.address "stmp.gmail.com" @@ -46,11 +47,11 @@ end time proc{|offset| Time.now} # computed attribute end -alternative syntax +### An example using alternative syntax ### Rc = O do |c| c.host = "localhost" c.port = 8080 c.mail.stmp.address "stmp.gmail.com" @@ -62,11 +63,11 @@ end c.time = proc{|offset| Time.now} end -a sugar syntax. _works in a file only_ +### An example of some sugar syntax. _works in a file only_ ### # file: guten/rc.rb development: adapter "mysql2" database "hello" @@ -78,40 +79,54 @@ adapter "mysql2" database "hello" username "guten" end -this is not pure ruby syntax, but it works. -**WARNNING**: must use \t to indent for this sugar syntax. -### initialize ### +**NOTE**: This is not pure ruby syntax, but it works. +In order for this to work, a tab ("\t") must be used for indention. -either way is fine +### Initialize ### +In order to initialize the configuration object either of the two ways can be used. + Rc = O.new Rc = O.require "guten/rc" # from file Rc = O do a 1 end - Rc = O[a:1] # from hash - Rc._merge! O_or_Hash + Rc = O[a: 1] # from a hash data + Rc._merge!(a: 1) file: "guten/rc.rb" a 1 +Initalize with a default value -### assignment & access ### + Rc = O.new + p Rc[:hello] #=> nil + Rc = O.new 1 + p Rc[:hello] #=> 1 + p Rc.hello #=> <#O> be careful here -either way is fine +### Assignment & Access ### +Flexibility has been built in to allow for various ways to assign configuration +data values and access the same values within your application. Here are some +examples of how this can be done: + +Assignment: + Rc.age 1 Rc.age = 1 Rc[:age] = 1 Rc["age"] = 1 - --- + +Access: + Rc.age #=> 1 Rc.age? #=> true Rc[:age] #=> 1 Rc["age"] #=> 1 --- @@ -119,20 +134,28 @@ age 2 c.age = 2 c[:age] = 2 end -### node ### +### Node ### - Rc.a.b.c 1 + Rc = O.new + Rc.a.b.c = 1 p Rc.a.b.c #=> <#Fixnum 1> p Rc.a.b #=> <#O> p Rc.a #=> <#O> - p Rc.i.dont.exists #=> <#O> #check use #_empty? + p Rc.i.dont.exists #=> <#O> -### variable & path ### + Rc = O.new + p Rc.a._empty? #=> true # if a node is empty? + Rc.a.b = 1 + p Rc.a._empty? #=> false + p O===Rc.a #=> true # if it is a node? + p O===Rc.a.b #=> false +### Variable & Path ### + O do age 1 p age #=> 1 my do age 2 @@ -144,22 +167,22 @@ p _.age #=> 1 _ is root end end end -### namespace ### +### Namespace ### -either way is fine +Either way is fine: O do mail.stmp.address "stmp.gmail.com" mail.stmp do address "stmp.gmail.com" end end -another example +Another namespace example: O do age 1 my do @@ -170,64 +193,69 @@ age 3 end end -### group ### +### Group ### -use namespace or use some seperate files like rails. +Use namespace or use some separate files like rails. config/ applications.rb environments/ development.rb test.rb production.rb -### computed attribute ### +### Computed attribute ### Rc = O do time proc{|n| Time.now} end p Rc.time # print current time. no need Rc.time.call() p Rc.time(2) # call time Rc.time = 2 # assign new value p Rc[:time] #=> <#Proc> -### semantic ### +### Semantic ### O do is_started no # yes ... end -for a list of semantic methods, see O::Semantics +Note: for a list of semantic methods, see O::Semantics -### hash compatibility ### +### Hash compatibility ### - Rc._keys # access hash method via `_method` +Internal, datas are stored as a Hash. You can access all hash methods via `_method` -### temporarily change ### + Rc = O.new + Rc.a = 1 + Rc._child #=> {:a=>1} + Rc._keys #=> [:a] + +### Temporarily change ### + Rc.a = 1 Rc._temp do Rc.a = 2 end p Rc.a #=> 1 -### access builtin method inside block ### +### Access built-in method inside block ### Rc = O do sleep 10 # is a data. Rc.sleep #=> 10 O.sleep 10 # call builtin 'sleep' method end -a list of blocked methods is in O::BUILTIN_METHODS +Note: for a list of blocked methods, see O::BUILTIN_METHODS +### Additional examples ### -### some other examples ### - O do name do first "Guten" last "Ye" is "#{first} #{last}" @@ -241,19 +269,15 @@ c.port = 8080 c.name do |c| c.first = "Guten" end - - Contributing ------------- -* join the project. -* report bugs/featues to issue tracker. -* fork it and pull a request. -* improve documentation. -* feel free to post any ideas. +* Feel free to join the project and make contributions (by submitting a pull request) +* Submit any bugs/features/ideas to github issue tracker +* Codeing style: https://gist.github.com/1105334 Install ---------- gem install o