Class: ActiveDoc::Descriptions::MethodArgumentDescription::DuckArgumentExpectation

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ArgumentExpectation

#additional_rdoc, find, #fulfilled?, inherited

Constructor Details

#initialize(argument) ⇒ DuckArgumentExpectation

Returns a new instance of DuckArgumentExpectation.



289
290
291
292
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 289

def initialize(argument)
  @respond_to = argument
  @respond_to = [@respond_to] unless @respond_to.is_a? Array
end

Class Method Details

.from(argument, options, proc) ⇒ Object



311
312
313
314
315
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 311

def self.from(argument, options, proc)
  if options[:duck]
    self.new(options[:duck])
  end
end

Instance Method Details

#condition?(value, args_with_vals) ⇒ Boolean

Returns:

  • (Boolean)


294
295
296
297
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 294

def condition?(value, args_with_vals)
  @failed_quacks = @respond_to.find_all {|quack| not value.respond_to? quack}
  @failed_quacks.empty?
end

#expectation_fail_to_sObject

Expected to… NOTE: Possible thread-safe problem



301
302
303
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 301

def expectation_fail_to_s
  "be respond to #{@respond_to.inspect}, missing #{@failed_quacks.inspect}"
end

#to_rdocObject



305
306
307
308
309
# File 'lib/active_doc/descriptions/method_argument_description.rb', line 305

def to_rdoc
  respond_to = @respond_to
  respond_to = respond_to.first if respond_to.size == 1
  "respond to #{respond_to.inspect}"
end