Class: ActiveDoc::Descriptions::MethodArgumentDescription

Inherits:
Object
  • Object
show all
Includes:
Traceable
Defined in:
lib/active_doc/descriptions/method_argument_description.rb

Direct Known Subclasses

Reference

Defined Under Namespace

Modules: Dsl, Traceable Classes: ArgumentExpectation, ArrayArgumentExpectation, ComplexConditionArgumentExpectation, DuckArgumentExpectation, OptionsHashArgumentExpectation, Reference, RegexpArgumentExpectation, TypeArgumentExpectation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Traceable

#origin_line

Constructor Details

#initialize(name, argument_expectation, origin, options = {}, &block) ⇒ MethodArgumentDescription

Returns a new instance of MethodArgumentDescription.



333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 333

def initialize(name, argument_expectation, origin, options = {}, &block)
  @name, @origin, @description = name, origin, options[:desc]
  @argument_expectations = []
  if found_expectation = ArgumentExpectation.find(argument_expectation, options, block)
    @argument_expectations << found_expectation
  elsif block
    raise "We haven't fount suitable argument expectations for given parameters"
  end
  
  if @argument_expectations.last.respond_to?(:last_line)
    @last_line = @argument_expectations.last.last_line
  end
end

Instance Attribute Details

#conjunctionObject

Returns the value of attribute conjunction.



330
331
332
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 330

def conjunction
  @conjunction
end

#nameObject (readonly)

Returns the value of attribute name.



329
330
331
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 329

def name
  @name
end

#origin_fileObject (readonly)

Returns the value of attribute origin_file.



329
330
331
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 329

def origin_file
  @origin_file
end

Instance Method Details

#last_lineObject



372
373
374
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 372

def last_line
  return @last_line || self.origin_line
end

#to_rdoc(hash = false) ⇒ Object



363
364
365
366
367
368
369
370
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 363

def to_rdoc(hash = false)
  name = hash ? @name.inspect : @name
  ret = "* +#{name}+"
  ret << expectations_to_rdoc.to_s
  ret << desc_to_rdoc.to_s
  ret << expectations_to_additional_rdoc.to_s
  return ret
end

#validate(args_with_vals) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 347

def validate(args_with_vals)
  argument_name = @name
  if arg_attributes = args_with_vals[@name]
    if arg_attributes[:required] || arg_attributes[:defined]
      current_value       = arg_attributes[:val]
      failed_expectations = @argument_expectations.find_all { |expectation| not expectation.fulfilled?(current_value, args_with_vals) }
      if !failed_expectations.empty?
        raise ArgumentError.new("Wrong value for argument '#{argument_name}'. Expected to #{failed_expectations.map { |expectation| expectation.expectation_fail_to_s }.join(",")}")
      end
    end
  else
    raise ArgumentError.new("Inconsistent method definition with active doc. Method was expected to have argument '#{argument_name}'")
  end
  return argument_name
end