Class: Mumukit::Templates::MulangExpectationsHook
Constant Summary
collapse
- LOGIC_SMELLS =
%w(UsesCut UsesFail UsesUnificationOperator HasRedundantReduction)
- FUNCTIONAL_SMELLS =
%w(HasRedundantParameter HasRedundantGuards)
- OBJECT_ORIENTED_SMELLS =
%w(DoesNullTest ReturnsNull)
- IMPERATIVE_SMELLS =
%w(HasRedundantLocalVariableReturn HasAssignmentReturn)
- EXPRESSIVENESS_SMELLS =
%w(HasTooShortIdentifiers HasWrongCaseIdentifiers HasMisspelledIdentifiers)
- GENERIC_SMELLS =
%w(IsLongCode HasCodeDuplication HasRedundantLambda HasRedundantIf DoesTypeTest HasRedundantBooleanComparison HasEmptyIfBranches)
ExpectationsHook::SOURCE_EXPECTATIONS, ExpectationsHook::SOURCE_EXPECTATION_EVALUATORS
Instance Attribute Summary
Attributes inherited from Hook
#config
Class Method Summary
collapse
Instance Method Summary
collapse
#compile
Methods inherited from Hook
#env, #initialize, #logger, #method_missing, #should_forward_to_config?, stateful_through, #t
#content_type
Constructor Details
This class inherits a constructor from Mumukit::Hook
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Mumukit::Hook
Class Method Details
.include_smells(value = true) ⇒ Object
74
75
76
77
78
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 74
def self.include_smells(value=true)
if value
include Mumukit::Templates::WithCodeSmells
end
end
|
Instance Method Details
#compile_content(content) ⇒ Object
56
57
58
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 56
def compile_content(content)
content
end
|
#compile_mulang_analysis(request, expectations) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# 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)
end
|
#default_smell_exceptions ⇒ Object
44
45
46
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 44
def default_smell_exceptions
[]
end
|
#domain_language ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 36
def domain_language
{
caseStyle: "CamelCase",
minimumIdentifierSize: 3,
jargon: []
}
end
|
#mulang_code(request) ⇒ Object
48
49
50
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 48
def mulang_code(request)
Mulang::Code.new(mulang_language, compile_content(request[:content]))
end
|
#mulang_language ⇒ Object
52
53
54
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 52
def mulang_language
language == 'Mulang' ? Mulang::Language::External.new : Mulang::Language::Native.new(language)
end
|
#parse_expectation(expectation) ⇒ Object
70
71
72
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 70
def parse_expectation(expectation)
expectation.deep_symbolize_keys.except(:tag)
end
|
#parse_response(response) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 60
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) ⇒ Object
14
15
16
|
# 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) ⇒ Object
29
30
31
32
33
|
# File 'lib/mumukit/templates/mulang_expectations_hook.rb', line 29
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
|