module CPEE::ModelManagement
Constants
- SERVER
Public Class Methods
fs_cp(models,old,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 82 def self::fs_cp(models,old,new) fname = File.join(models,old) fnname = File.join(models,new) FileUtils.cp(fname,fnname) File.delete(fname + '.active',fnname + '.active') rescue nil File.delete(fname + '.active-uuid',fnname + '.active-uuid') rescue nil FileUtils.cp(fname + '.attrs',fnname + '.attrs') rescue nil end
fs_mv(models,old,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 74 def self::fs_mv(models,old,new) fname = File.join(models,old) fnname = File.join(models,new) FileUtils.mv(fname,fnname) rescue nil File.delete(fname + '.active',fnname + '.active') rescue nil File.delete(fname + '.active-uuid',fnname + '.active-uuid') rescue nil FileUtils.mv(fname + '.attrs',fnname + '.attrs') rescue nil end
fs_rm(models,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 90 def self::fs_rm(models,new) fname = File.join(models,new) FileUtils.rm_rf(fname) File.delete(fname + '.active') rescue nil File.delete(fname + '.active-uuid') rescue nil File.delete(fname + '.attrs') rescue nil end
fs_shift(models,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 97 def self::fs_shift(models,new) fname = File.join(models,new) File.delete(fname + '.active') rescue nil File.delete(fname + '.active-uuid') rescue nil end
get_dn(dn)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 150 def self::get_dn(dn) #{{{ if dn dn.split(',').map{ |e| e.split('=',2) }.to_h else { 'GN' => 'Christine', 'SN' => 'Ashcreek' } end end
git_commit(models,new,author)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 69 def self::git_commit(models,new,author) rp = File.realpath(models) crb = File.join(__dir__,'commit.rb') system 'ruby ' + crb + ' ' + [rp, new, author].shelljoin + ' &' end
git_dir(models,file)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 103 def self::git_dir(models,file) return nil if file.nil? cdir = Dir.pwd tdir = File.dirname(file) Dir.chdir(File.join(models,tdir)) res = `git rev-parse --absolute-git-dir 2>/dev/null` Dir.chdir(cdir) res == '' ? nil : res end
git_mv(models,old,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 34 def self::git_mv(models,old,new) cdir = Dir.pwd Dir.chdir(File.join(models,File.dirname(old))) p1 = Pathname.new(File.dirname(old)) p2 = Pathname.new(File.dirname(new)) told = File.basename(old) tnew = File.join(p1.relative_path_from(p1).to_s,File.basename(new)) `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple mv "#{told}" "#{tnew}" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{told + '.active'}" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{told + '.active-uuid'}" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple mv "#{told + '.attrs'}" "#{tnew + '.author'}" 2>/dev/null` Dir.chdir(cdir) CPEE::ModelManagement::fs_mv(models,old,new) # fallback end
git_rm(models,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 48 def self::git_rm(models,new) cdir = Dir.pwd Dir.chdir(File.join(models,File.dirname(new))) tnew = File.basename(new) `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{tnew}" 2>/dev/null` FileUtils.rm_rf(tnew) `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{tnew}.active" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{tnew}.active-uuid" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{tnew}.attrs" 2>/dev/null` Dir.chdir(cdir) CPEE::ModelManagement::fs_rm(models,new) # fallback end
git_shift(models,new)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 60 def self::git_shift(models,new) cdir = Dir.pwd Dir.chdir(File.join(models,File.dirname(new))) nnew = File.basename(new) `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{nnew}.active" 2>/dev/null` `git -c user.name='Christine Ashcreek' -c user.email=dev@null.com -c push.default=simple rm -rf "#{nnew}.active-uuid" 2>/dev/null` Dir.chdir(cdir) CPEE::ModelManagement::fs_shift(models,new) # fallback end
implementation(opts)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 606 def self::implementation(opts) opts[:connections] = [] Proc.new do on resource do run GetList, :main, opts[:views], opts[:models] if get 'stage' run GetListFull, opts[:views], opts[:models] if get 'full' run GetStages, opts[:themes] if get 'stages' run Create, :main, :cre, opts[:views], opts[:connections], opts[:templates], opts[:models] if post 'item' run Create, :main, :dup, opts[:views], opts[:connections], opts[:templates], opts[:models] if post 'duplicate' run CreateDir, opts[:connections], opts[:models] if post 'dir' run Active, opts[:connections] if sse on resource '[a-zA-Z0-9öäüÖÄÜ _-]+\.dir' do run GetList, :sub, opts[:views], opts[:models] if get 'stage' run Create, :sub, :cre, opts[:views], opts[:connections], opts[:templates], opts[:models] if post 'item' run Create, :sub, :dup, opts[:views], opts[:connections], opts[:templates], opts[:models] if post 'duplicate' run DeleteDir, opts[:connections], opts[:models] if delete run RenameDir, opts[:connections], opts[:models] if put 'name' on resource '[a-zA-Z0-9öäüÖÄÜ _-]+\.xml' do run DeleteItem, :sub, opts[:connections], opts[:models] if delete run GetItem, :sub, opts[:models] if get run PutItem, :sub, opts[:connections], opts[:models] if put 'content' run RenameItem, :sub, opts[:connections], opts[:models] if put 'name' run MoveItem, :sub, opts[:connections], opts[:models] if put 'dirname' run ShiftItem, :sub, opts[:connections], opts[:themes], opts[:models] if put 'newstage' on resource 'open' do run OpenItem, :sub, opts[:instantiate], opts[:cockpit], opts[:views], false, opts[:models] if get 'stage' end on resource 'open-new' do run OpenItem, :sub, opts[:instantiate], opts[:cockpit], opts[:views], true, opts[:models] if get 'stage' end end end on resource '[a-zA-Z0-9öäüÖÄÜ _-]+\.xml' do run DeleteItem, :main, opts[:connections], opts[:models] if delete run GetItem, :main, opts[:models] if get run PutItem, :main, opts[:connections], opts[:models] if put 'content' run RenameItem, :main, opts[:connections], opts[:models] if put 'name' run MoveItem, :main, opts[:connections], opts[:models] if put 'dirname' run ShiftItem, :main, opts[:connections], opts[:themes], opts[:models] if put 'newstage' on resource 'open' do run OpenItem, :main, opts[:instantiate], opts[:cockpit], opts[:views], false, opts[:models] if get 'stage' end on resource 'open-new' do run OpenItem, :main, opts[:instantiate], opts[:cockpit], opts[:views], true, opts[:models] if get 'stage' end end end end end
notify(conns,op,models,f,s=nil)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 157 def self::notify(conns,op,models,f,s=nil) #{{{ what = if f =~ /\.dir$/ if op == 'delete' { :op => op, :type => :dir, :name => File.basename(f) } else attrs = JSON::load File.open(f + '.attrs') { :op => op, :type => :dir, :name => File.basename(f), :creator => attrs['creator'], :date => File.mtime(f).xmlschema } end else if op == 'delete' { :op => op, :type => :file, :name => f.sub(Regexp.compile(File.join(models,'/')),'') } else attrs = JSON::load File.open(f + '.attrs') fstage = attrs['design_stage'] rescue 'draft' { :op => op, :type => :file, :name => f.sub(Regexp.compile(File.join(models,'/')),''), :creator => attrs['creator'], :author => attrs['author'], :stage => fstage, :date => File.mtime(f).xmlschema } end end what[:source] = s.sub(/models\//,'') unless s.nil? conns.each do |e| e.send what end end
op(author,op,models,new,old=nil)
click to toggle source
# File lib/cpee-model-management/implementation.rb, line 113 def self::op(author,op,models,new,old=nil) #{{{ git_ndir = CPEE::ModelManagement::git_dir(models,new) git_odir = CPEE::ModelManagement::git_dir(models,old) if op == 'rm' && !git_ndir.nil? git_rm models, new git_commit models, new, author elsif op == 'shift' && !git_ndir.nil? git_shift models, new git_commit models, new, author elsif op == 'mv' && (!git_ndir.nil? || !git_odir.nil?) if git_ndir == git_odir git_mv models, old, new git_commit models, new, author elsif git_ndir != git_odir && !git_ndir.nil? && !git_odir.nil? fs_cp models, old, new git_rm models, old git_commit models, old, author git_commit models, new, author elsif git_ndir != git_odir && git_ndir.nil? fs_cp models, old, new git_rm models, old git_commit models, old, author elsif git_ndir != git_odir && git_odir.nil? fs_mv models, old, new git_commit models, new, author end elsif !git_ndir.nil? git_commit models, new, author else case op when 'mv'; fs_mv(models,old,new) when 'rm'; fs_rm(models,new) when 'shift'; fs_shift(models,new) end end end