Class: CPEE::ModelManagement::GetList

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

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/cpee-model-management/implementation.rb', line 183

def response
  where = @a[0] == :main ? '' : @r.map{ |d| Riddl::Protocols::Utils::unescape(d) }.join('/')
  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] }

  ret = JSON::pretty_generate(names)
  @headers << Riddl::Header.new('CPEE-MOMA-FINGERPRINT', Digest::SHA1.hexdigest(ret))

  Riddl::Parameter::Complex.new('list','application/json',ret)
end