Class: CPEE::ModelManagement::GetListFull

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee-model-management/implementation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/cpee-model-management/implementation.rb', line 206

def response
  views = @a[0]
  models = @a[1]
  stage = [@p[0]&.value] || ['draft']
  stage << views[stage[0]] if views && views[stage[0]]

  names = Dir.glob(File.join(models,'*.dir/*.xml')).map do |f|
    attrs = JSON::load File.open(f + '.attrs')
    { :type => :file, :name => File.join(File.basename(File.dirname(f)),File.basename(f)), :creator => attrs['creator'], :date => File.mtime(f).xmlschema }
  end.compact.uniq.sort_by{ |e| e[:name] } + Dir.glob(File.join(models,'*.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