class Minireq::Data::DslFileMgr

Public Class Methods

new(file_name, dsl_class) click to toggle source

TODO @block for write_dsl_function?

# File lib/minireq/data/dsl_file_mgr.rb, line 10
def initialize(file_name, dsl_class)
  @file_name = file_name
  @dsl_class = dsl_class
end

Public Instance Methods

calc() click to toggle source
# File lib/minireq/data/dsl_file_mgr.rb, line 68
def calc
  if !file_exist?
    puts "#{@file_name} does not exist. Operation aborted."
    return
  end
  dsl = @dsl_class.new
  indoc{dsl.load(@file_name)}

  puts "#{@file_name} calculation result:"
  dsl.calculate.each{|k, v| puts "#{k}: #{v}"}
end
check() click to toggle source
# File lib/minireq/data/dsl_file_mgr.rb, line 46
def check
  if !file_exist?
    puts "#{@file_name} does not exist. Operation aborted."
    return
  end
  doc = get_document
  dsl = @dsl_class.new
  indoc { dsl.load(@file_name) }

  doc_ids = doc.get_ids
  dsl_ids = dsl.objects

  missed = doc_ids - dsl_ids
  puts "The next requirements are missed in #{@file_name}: #{missed.join(', ')}" unless missed.empty?

  wrong  = dsl_ids - doc_ids
  puts "The next traces are wrong in #{@file_name}: #{wrong.join(', ')}" unless wrong.empty?

  return if !missed.empty? || !wrong.empty?
  puts "#{@file_name} checked. Everything is fine!"
end
create() click to toggle source
# File lib/minireq/data/dsl_file_mgr.rb, line 19
def create
  if file_exist?
    puts "#{@file_name} already exist. Operation aborted."
    return
  end
  doc = get_document
  dsl = @dsl_class.new
  doc.visit { |r| dsl.dsl_func(r) }
  indoc { dsl.save(@file_name) }
  puts "#{@file_name} created successfully."
end
file_exist?() click to toggle source
# File lib/minireq/data/dsl_file_mgr.rb, line 15
def file_exist?
  indoc { File.exist?(@file_name) }
end
update() click to toggle source
# File lib/minireq/data/dsl_file_mgr.rb, line 31
def update
  if !file_exist?
    puts "#{@file_name} does not exist. Operation aborted."
    return
  end
  doc = get_document
  dsl = @dsl_class.new
  indoc { dsl.load(@file_name) }
  # TODO now it add skip() function if r.body.empty?
  #      dsl file already contain skip() but now r.body.empty? false
  doc.visit{|r| dsl.dsl_func(r) unless dsl.include?(r.id)}
  indoc { dsl.save(@file_name) }
  puts "#{@file_name} updated successfully."
end