Class: Roodi::Checks::ParameterNumberCheck
- Defined in:
- lib/roodi/checks/parameter_number_check.rb
Constant Summary collapse
- DEFAULT_PARAMETER_COUNT =
3
Instance Method Summary collapse
- #evaluate(node) ⇒ Object
-
#initialize(options = {}) ⇒ ParameterNumberCheck
constructor
A new instance of ParameterNumberCheck.
- #interesting_nodes ⇒ Object
Methods inherited from Check
#add_error, #errors, #evaluate_node_at_line, #position
Constructor Details
#initialize(options = {}) ⇒ ParameterNumberCheck
Returns a new instance of ParameterNumberCheck.
11 12 13 14 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 11 def initialize( = {}) super() @parameter_count = ['parameter_count'] || DEFAULT_PARAMETER_COUNT end |
Instance Method Details
#evaluate(node) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 20 def evaluate(node) method_name = node[1] arguments = node[2][1][1] parameter_count = arguments.inject(-1) { |count, each| count = count + (each.class == Symbol ? 1 : 0) } add_error({ :method => method_name, :parameters => parameter_count }) unless parameter_count <= @parameter_count end |
#interesting_nodes ⇒ Object
16 17 18 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 16 def interesting_nodes [:defn] end |