class Mumukit::Templates::MulangExpectationsHook
Constants
- EXPRESSIVENESS_SMELLS
- FUNCTIONAL_SMELLS
- GENERIC_SMELLS
- IMPERATIVE_SMELLS
- LOGIC_SMELLS
- OBJECT_ORIENTED_SMELLS
Public Class Methods
include_smells(value=true)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 89 def self.include_smells(value=true) if value include Mumukit::Templates::WithCodeSmells end end
Public Instance Methods
autocorrection_rules()
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 52 def autocorrection_rules {} end
compile_content(content)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 71 def compile_content(content) content end
compile_mulang_analysis(request, expectations)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 18 def compile_mulang_analysis(request, expectations) mulang_code(request).analysis({ expectations: expectations[:ast], customExpectations: expectations[:custom], smellsSet: { tag: 'AllSmells', exclude: (expectations[:exceptions] + default_smell_exceptions) }, domainLanguage: domain_language }.merge({ originalLanguage: original_language, autocorrectionRules: autocorrection_rules.try { |it| positive_and_negative it }.presence, normalizationOptions: normalization_options(request).presence }.compact)) end
default_smell_exceptions()
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 59 def default_smell_exceptions [] end
domain_language()
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 40 def domain_language { caseStyle: "CamelCase", minimumIdentifierSize: 3, jargon: [] } end
mulang_code(request)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 63 def mulang_code(request) Mulang::Code.new(mulang_language, compile_content(request[:content])) end
mulang_language()
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 67 def mulang_language language == 'Mulang' ? Mulang::Language::External.new : Mulang::Language::Native.new(language) end
normalization_options(request)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 48 def normalization_options(request) request.dig(:settings, :normalization_options) || {} end
original_language()
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 56 def original_language end
parse_expectation(expectation)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 85 def parse_expectation(expectation) expectation.deep_symbolize_keys.except(:tag) end
parse_response(response)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 75 def parse_response(response) if response['tag'] == 'AnalysisFailed' raise Mumukit::CompilationError, response['reason'] end response['expectationResults'].map do |it| {result: it['result'], expectation: parse_expectation(it['expectation'])} end end
run!(spec)
click to toggle source
Calls superclass method
Mumukit::Templates::ExpectationsHook#run!
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 14 def run!(spec) super(spec) + run_mulang_analysis(compile_mulang_analysis(spec[:request], spec[:expectations])) end
run_mulang_analysis(analysis)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 34 def run_mulang_analysis(analysis) parse_response Mulang.analyse(analysis) rescue JSON::ParserError raise Mumukit::CompilationError, "Can not handle mulang results for analysis #{analysis}" end
Private Instance Methods
positive_and_negative(rules)
click to toggle source
# File lib/mumukit/templates/mulang_expectations_hook.rb, line 97 def positive_and_negative(rules) rules.flat_map { |k, v| [[k, v], ["Not:#{k}", "Not:#{v}"]] }.to_h end