README.md in o-1.0.2 vs README.md in o-2.0.0

- old
+ new

@@ -5,76 +5,234 @@ **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/> +Features +-------- + +* support variable, computed attribute +* DSL syntax in pure ruby +* tree way to do configration. +* hash compatibility + Introduction ------------- - option = O.new +do configuration at three levels: system, user, cmdline - # assigment - option["a"] = 1 - option[:a] = 1 - option.a = 1 + lib/guten/rc.rb # system level + ~/.gutenrc # user level + $ guten --list # cmdline level + + module Guten + Rc = O.require("guten/rc") + O.require("~/.gutenrc") + Rc.list = true + end - # access - option["a"] - option[:a] - option.a - option.a? #=> true - #access Hash methods. - option._keys #=> [:a] +### a completed example ### -assign default value + Rc = O do + host "localhost" + port 8080 + mail.stmp.address "stmp.gmail.com" - option = O.new - option.a #=> nil + my.development do # namespace + adapter "mysql2" + database "hello" + username "guten" + end - option = O.new 0 - option.a #=> 0 + time proc{|offset| Time.now} # computed attribute + end -another syntax +alternative syntax - option = O do - base = 1 - @a = base - @b = base + 1 + Rc = O do |c| + c.host = "localhost" + c.port = 8080 + c.mail.stmp.address "stmp.gmail.com" + + my.development do |c| + c.adapter = "mysql2" + c.database = "hello" + c.username = "guten" + end + + c.time = proc{|offset| Time.now} end - option.a #=> 1 - option.b #=> 2 +### initialize ### -read option from a file +either way is fine - # ~/.gutenrc - @a = 1 - @path = Pathname('/home') + 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 - # a.rb - require "pathname" - option = O.load("~/.gutenrc") - option.a #=> 1 +file: "guten/rc.rb" -configuration file ------------------- + a 1 - use instance variable to export field. - base = 1 - @a = base - @b = O do - p @a #=> nil # instance variable can't pass into block - p base #=> 1 # local variable can pass into block - @a = base + 1 +### assignment & access ### + +either way is fine + + Rc.age 1 + Rc.age = 1 + Rc[:age] = 1 + Rc["age"] = 1 + --- + Rc.age #=> 1 + Rc.age? #=> true + Rc[:age] #=> 1 + Rc["age"] #=> 1 + --- + O do |c| + age 2 + c.age = 2 + c[:age] = 2 end - - # after O.load(file) - option.a #=> 1 - option.b.a #=> 2 +### node ### + + 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? + +### variable & path ### + + O do + age 1 + p age #=> 1 + my do + age 2 + friend do + age 3 + p age #=> 3 + p __.age #=> 2 relative + p ___.age #=> 1 + p _.age #=> 1 root + end + end + end + +### namespace ### + +either way is fine + + O do + mail.stmp.address "stmp.gmail.com" + mail.stmp do + address "stmp.gmail.com" + end + end + +another example + + O do + age 1 + + my do + age 2 + end + + my.friend do + age 3 + end + end + + +### group ### + +use namespace or use some seperate files like rails. + + config/ + applications.rb + environments/ + development.rb + test.rb + production.rb + +### 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 ### + + O do + is_started no # yes ... + end + +for a list of semantic methods, see O::Semantics + +### hash compatibility ### + + Rc._keys # access hash method via `_method` + +### temporarily change ### + + Rc.a = 1 + Rc._temp do + Rc.a = 2 + end + p Rc.a #=> 1 + + +### access builtin 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 + +### another sugar syntax ### + +it likes yaml-style. this way is experiment. used in file syntax only + + # file: guten/rc.rb + a: + b 1 + c: + d 1 + + #=> + + a do + b 1 + c do + d 1 + end + end + +**WARNNING**: must use \t to indent + +### some other examples ### + + name do + first "Guten" + last "Ye" + is "#{first} #{last}" + end + + Contributing ------------- * join the project. * report bugs/featues to issue tracker. @@ -88,10 +246,13 @@ gem install o Resources --------- -[configuration](https://github.com/ahoward/configuration) +* [konfigurator](https://github.com/nu7hatch/konfigurator) Small and flexible configuration toolkit inspired i.a. by Sinatra settings +* [configatron](https://github.com/markbates/configatron) A super cool, simple, and feature rich configuration system for Ruby apps +* [simpleconfig](https://github.com/lukeredpath/simpleconfig) make application-wide configuration settings easy to set and access in an object-oriented fashion +* [configuration](https://github.com/ahoward/configuration) pure ruby scoped configuration files Copyright --------- Copyright &copy; 2011 by Guten. this library released under MIT-LICENSE, See {file:LICENSE} for futher details.