Module: DyndocWorld
- Defined in:
- lib/dyndoc-world.rb
Constant Summary collapse
- @@root =
nil
- @@public =
nil
Class Method Summary collapse
- .cfg(admin = nil) ⇒ Object
- .open_prj_file(prj_file) ⇒ Object
-
.prj_file?(yml) ⇒ Boolean
access ## prj is to give access for a user or a group of users if prj or prj/secret is undefined it is accessible.
- .public_root(public_root = nil) ⇒ Object
- .root(root = nil) ⇒ Object
-
.save_prj_file(prj_file, content) ⇒ Object
file ## from yml ex: public/<user>/<pathname> edit/<user>/<pathname> dynworld/<user>/<pathname>.
Class Method Details
.cfg(admin = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dyndoc-world.rb', line 18 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.exist? secret return cfg end |
.open_prj_file(prj_file) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/dyndoc-world.rb', line 73 def DyndocWorld.open_prj_file(prj_file) res={success: false} if File.exist? prj_file res[:content]=File.read(prj_file) res[:success]=true end return res end |
.prj_file?(yml) ⇒ Boolean
access ## prj is to give access for a user or a group of users if prj or prj/secret is undefined it is accessible
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dyndoc-world.rb', line 28 def DyndocWorld.prj_file?(yml) prj=yml["prj"] || yml["project"] || "default" admin=(prj=="admin") cfg=DyndocWorld.cfg(admin) cfg=cfg[prj] unless admin return nil unless cfg and yml["file"] parts=yml["file"].split("/") p [:parts,parts] root=parts.shift p [:root,root] user=parts.shift ##DEBUG: p [:"yml?", cfg, yml, (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../"))] if (cfg and yml and ((cfg["secret"] || "none") == (yml["secret"] || "none")) and yml["file"] and !(yml["file"].include? "../")) and ((cfg["users"] || []).include? user) prj_file=nil if ["public","edit","dynworld"].include? root prj_subdir=cfg["subdir"] || "" case root when "public" prj_file=File.join(DyndocWorld.public_root,"users",user) prj_file=(Dir.exist? prj_file) ? File.join(prj_file,prj_subdir,parts) : "" when "edit" prj_file=File.join(DyndocWorld.public_root,"users",user,".edit") prj_file=(Dir.exist? prj_file) ? File.join(prj_file,prj_subdir,parts) : "" when "dynworld" prj_file=File.join(DyndocWorld.root,user,prj_subdir,parts) end end end p [:prj_file,prj_file] return prj_file end |
.public_root(public_root = nil) ⇒ Object
13 14 15 16 |
# File 'lib/dyndoc-world.rb', line 13 def DyndocWorld.public_root(public_root=nil) @@public=public_root if public_root return @@public end |
.root(root = nil) ⇒ Object
8 9 10 11 |
# File 'lib/dyndoc-world.rb', line 8 def DyndocWorld.root(root=nil) @@root=root if root return @@root end |
.save_prj_file(prj_file, content) ⇒ Object
file ## from yml ex: public/<user>/<pathname>
edit/<user>/<pathname>
dynworld/<user>/<pathname>
66 67 68 69 70 71 |
# File 'lib/dyndoc-world.rb', line 66 def DyndocWorld.save_prj_file(prj_file,content) FileUtils.mkdir_p File.dirname prj_file File.open(prj_file,"w") {|f| f << content.strip } end |