Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Created October 19, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlindberg/08544b3706e3b8be45b2c0387b079152 to your computer and use it in GitHub Desktop.
Save hlindberg/08544b3706e3b8be45b2c0387b079152 to your computer and use it in GitHub Desktop.
Start of ABC metric for Puppet
# AbcMetric sample - obviously in the wrong name space...
module Puppet::Pops
module Validation
class AbcMetric
attr_reader :assignment_count
def initialize()
@@abc_visitor ||= Visitor.new(nil, "abc", 0, 0)
@assignment_count = 0
end
# Performs regular validity check
def compute_abc(target)
target.eAllContents.each {|m| abc(m) }
[@assignment_count, 0, 0]
end
def abc(o)
@@abc_visitor.visit_this_0(self, o)
end
def abc_Object(o)
# nothing to count here
end
def abc_AssignmentExpression(o)
@assignment_count += 1
end
end
end
end
require 'puppet'
require 'puppet/pops/validation/abc_metric'
abc_metric = Puppet::Pops::Validation::AbcMetric.new
parser = Puppet::Pops::Parser::EvaluatingParser.new
program = parser.parse_string("$a = 10; $b = 20")
puts abc_metric.compute_abc(program.model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment