Class: ActiveDoc::Descriptions::MethodArgumentDescription
- Inherits:
-
Object
- Object
- ActiveDoc::Descriptions::MethodArgumentDescription
- Includes:
- Traceable
- Defined in:
- lib/active_doc/descriptions/method_argument_description.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Dsl, Traceable Classes: ArgumentExpectation, ArrayArgumentExpectation, ComplexConditionArgumentExpectation, DuckArgumentExpectation, OptionsHashArgumentExpectation, Reference, RegexpArgumentExpectation, TypeArgumentExpectation
Instance Attribute Summary collapse
-
#conjunction ⇒ Object
Returns the value of attribute conjunction.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#origin_file ⇒ Object
readonly
Returns the value of attribute origin_file.
Instance Method Summary collapse
-
#initialize(name, argument_expectation, origin, options = {}, &block) ⇒ MethodArgumentDescription
constructor
A new instance of MethodArgumentDescription.
- #last_line ⇒ Object
- #to_rdoc(hash = false) ⇒ Object
- #validate(args_with_vals) ⇒ Object
Methods included from Traceable
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, = {}, &block) @name, @origin, @description = name, origin, [:desc] @argument_expectations = [] if found_expectation = ArgumentExpectation.find(argument_expectation, , 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
#conjunction ⇒ Object
Returns the value of attribute conjunction.
330 331 332 |
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 330 def conjunction @conjunction end |
#name ⇒ Object (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_file ⇒ Object (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_line ⇒ Object
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 |