Module: Build2Spec::FakingMethods

Included in:
UnknownType
Defined in:
lib/build2spec.rb

Constant Summary collapse

@@unknown_types =
[]

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/build2spec.rb', line 404

def method_missing(name, *args, &block)
  retval = FakingMethods::record_method_spec(return_type_nesting, faked_methods, name, args, block)

  if Module === self
    define_method(name, instance_method(:initialize))
  else
    self.class.class_eval do 
      define_method(name, self.instance_method(:initialize))
    end
  end

  return retval
end

Class Method Details

.current_methodObject



360
361
362
363
364
365
366
367
# File 'lib/build2spec.rb', line 360

def self.current_method
  called_from = caller.grep(/in `/)[1]
  if (m = /in `([^']*)/.match called_from)
    return m[1].intern
  else
    raise RuntimeError, called_from
  end
end

.record_method_spec(nesting, faked_methods, name, args, block) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/build2spec.rb', line 369

def self.record_method_spec(nesting, faked_methods, name, args, block)
  method_spec = []
  if (method_spec = faked_methods[name]).nil?
    arity = args.length

    result = UnknownType.create(nesting)
    if name == :initialize
      result = nil
    elsif /\?$/ =~ name.to_s
      result = false
    end

    if UnknownType === result
      @@unknown_types << result
    end

    method_spec = [arity..arity, (not block.nil?), result]
    faked_methods[name] = method_spec
  else
    unless (method_spec[0].include? args.length)
      if(method_spec[0].begin > args.length)
        method_spec[0] = args.length..method_spec[0].end
      else
        method_spec[0] = method_spec[0].begin..args.length
      end
    end

    method_spec[1] ||= !(block.nil?)
  end

  #p [:rms, name, method_spec]

  return method_spec[2]
end

.unknown_typesObject



356
357
358
# File 'lib/build2spec.rb', line 356

def self.unknown_types
  return @@unknown_types
end

Instance Method Details

#initialize(*args, &block) ⇒ Object



351
352
353
# File 'lib/build2spec.rb', line 351

def initialize(*args, &block)
  return FakingMethods::record_method_spec(return_type_nesting, faked_methods, FakingMethods.current_method, args, block)
end