Sha256: 2bf24e412d8e478b6dc3d2a46081c9975ba335d7d3fb3c8c8bf1118d6ef10128
Contents?: true
Size: 1.99 KB
Versions: 3
Compression:
Stored size: 1.99 KB
Contents
require 'yaml' module DyndocWorld @@root=nil @@public=nil def DyndocWorld.root(root=nil) @@root=root if root return @@root end def DyndocWorld.public_root(public_root=nil) @@public=public_root if public_root return @@public end def DyndocWorld.cfg(admin=nil) cfg={} secret = File.join(DyndocWorld.root,admin ? ".admin.yml" : ".secret.yml") cfg = YAML::load_file(secret) if DyndocWorld.root and File.exists? secret return cfg end ## access ## ## prj is to give access for a user or a group of users ## if prj or prj/secret is undefined it is accessible def DyndocWorld.yml?(prj,yml) admin=(prj=="admin") cfg=DyndocWorld.cfg(admin) cfg=cfg[prj] unless admin return true unless cfg ##DEBUG: p [:"yml?", cfg, yml, (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../"))] return (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../")) end ## file ## ## from yml ## ex: public/<user>/<pathname> ## edit/<user>/<pathname> ## dynworld/<user>/<pathname> def DyndocWorld.prj_file(yml,content) success,prj_file=false,"" parts=yml["file"].split("/") p [:parts,parts] root=parts.shift p [:root,root] if ["public","edit","dynworld"].include? root user=parts.shift case root when "public" prj_file=File.join(DyndocWorld.public_root,"users",user) prj_file=(Dir.exists? prj_file) ? File.join(prj_file,parts) : "" when "edit" prj_file=File.join(DyndocWorld.public_root,"users",user,".edit") prj_file=(Dir.exists? prj_file) ? File.join(prj_file,parts) : "" when "dynworld" prj_file=File.join(DyndocWorld.root,user,parts) end end p [:prj_file,prj_file] unless prj_file.empty? FileUtils.mkdir_p File.dirname prj_file File.open(prj_file,"w") {|f| if root == "edit" f << yml.to_yaml f << "---\n" end f << content.strip } success=true end return success end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dyndoc-ruby-1.4.1 | lib/dyndoc-world.rb |
dyndoc-ruby-1.4.0 | lib/dyndoc-world.rb |
dyndoc-ruby-1.3.9 | lib/dyndoc-world.rb |