Created
October 19, 2016 19:01
-
-
Save hlindberg/08544b3706e3b8be45b2c0387b079152 to your computer and use it in GitHub Desktop.
Start of ABC metric for Puppet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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