Sha256: 7b1104d71f2b3c5ce062d99554ffdee0bb6daff58d34b6a9f599d6c52009f19e

Contents?: true

Size: 1.95 KB

Versions: 7

Compression:

Stored size: 1.95 KB

Contents

require 'bundler/gem_tasks'
require 'junoser/development'
require 'nokogiri'
require 'pathname'
require 'rake/testtask'

xsd_path = File.join(__dir__, 'tmp/junos-system-21.2.xsd')
rule_path = File.join(__dir__, 'tmp/rule.rb')
ruby_parser_path = File.join(__dir__, 'lib/junoser/parser.rb')
js_parser_path = File.join(__dir__, 'tmp/junos.js')

def open_files(input, output, &block)
  i = open(input)
  o = open(output, 'w')

  yield i, o

  i.close
  o.close
end

def move_wildcards(element)
  ['ipaddr', 'ipv6addr', 'ipprefix'].each do |pattern|
    element.xpath(%[.//xsd:element[@type="#{pattern}"]/xsd:annotation/xsd:appinfo/flag[text()="nokeyword"]/../../..]).each do |wildcard|
      parent = wildcard.parent
      removed = wildcard.remove
      parent << removed
    end
  end
end

namespace :build do
  desc 'Build an intermediate config hierarchy'
  task :config do
    open_files(xsd_path, rule_path) do |input, output|
      Nokogiri::XML(input).root.remove_unused.xpath('/xsd:schema/*').each do |e|
        move_wildcards e # Move wildcard elements to the end of siblings as they capture keywords unexpectedly
        output.puts e.to_config
      end
    end
  end

  desc 'Build ruby parser'
  task :rule do
    open_files(rule_path, ruby_parser_path) do |input, output|
      output.puts Junoser::Ruler.new(input).to_rule
    end
  end

  desc 'Build javascript parser'
  task :jsrule do
    open_files(rule_path, js_parser_path) do |input, output|
      output.puts Junoser::JsRuler.new(input).to_rule
    end
  end
end

task 'find-srx-methods' do
  vsrx = File.read('vsrx.rb')
  vmx = File.read('lib/junoser/parser.rb')

  vsrx.scan(/^ +([0-9a-z_]+) *$/).flatten.uniq.sort.each do |method|
    next if ['arg', 'end', 'ipaddr', 'time'].include?(method)

    puts method unless vsrx =~ /rule\(:#{method}\)/m || vmx =~ /rule\(:#{method}\)/m
  end
end

Rake::TestTask.new do |t|
  t.libs << 'test'

  t.verbose = true
  t.warning = false
end

desc 'Run tests'
task default: :test

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
junoser-0.5.6 Rakefile
junoser-0.5.5 Rakefile
junoser-0.5.4 Rakefile
junoser-0.5.3 Rakefile
junoser-0.5.2 Rakefile
junoser-0.5.1 Rakefile
junoser-0.5.0 Rakefile