class CPEE::ModelManagement::GetList

Public Instance Methods

response() click to toggle source
# File lib/cpee-model-management/implementation.rb, line 181
def response
  where = @a[0] == :main ? '' : Riddl::Protocols::Utils::unescape(@r.last)
  views = @a[1]
  models = @a[2]
  stage = [@p[0]&.value] || ['draft']
  stage << views[stage[0]] if views && views[stage[0]]

  names = Dir.glob(File.join(models,where,'*.dir')).map do |f|
    attrs = JSON::load File.open(f + '.attrs')
    { :type => :dir, :name => File.basename(f), :creator => attrs['creator'], :date => File.mtime(f).xmlschema }
  end.compact.uniq.sort_by{ |e| e[:name] } + Dir.glob(File.join(models,where,'*.xml')).map do |f|
    attrs = JSON::load File.open(f + '.attrs')
    fstage = attrs['design_stage'] rescue 'draft'
    { :type => :file, :name => File.basename(f), :creator => attrs['creator'], :author => attrs['author'], :guarded => attrs['guarded'], :guarded_id => attrs['guarded_id'], :stage => fstage, :date => File.mtime(f).xmlschema } if stage.include?(fstage)
  end.compact.uniq.sort_by{ |e| e[:name] }

  Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(names))
end