Module: BBLib::Delegator::ClassMethods

Defined in:
lib/bblib/core/mixins/delegator.rb

Instance Method Summary collapse

Instance Method Details

#_ancestor_delegate_fastObject



70
71
72
73
74
75
76
77
# File 'lib/bblib/core/mixins/delegator.rb', line 70

def _ancestor_delegate_fast
  ancestors.reverse.find do |anc|
    next if anc == self
    next unless anc.respond_to?(:delegate_fast)
    return anc.delegate_fast
  end
  true
end

#ancestor_delegatesObject



83
84
85
86
87
88
# File 'lib/bblib/core/mixins/delegator.rb', line 83

def ancestor_delegates
  ancestors.reverse.flat_map do |anc|
    next if anc == self || !anc.respond_to?(:delegates)
    anc.delegates
  end.compact.uniq
end

#delegate_fast(*args) ⇒ Object

When turned on the respond_to_missing method is left unchanged. This GREATLY speeds up the instantiation of classes with lots of calls to respond_to?



57
58
59
60
# File 'lib/bblib/core/mixins/delegator.rb', line 57

def delegate_fast(*args)
  return @delegate_fast ||= _ancestor_delegate_fast if args.empty?
  @delegate_fast = args.first ? true : false
end

#delegate_to(*mthds) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/bblib/core/mixins/delegator.rb', line 62

def delegate_to(*mthds)
  mthds.flatten.each do |method|
    next if delegates.include?(method)
    delegates << method
  end
  true
end

#delegatesObject



79
80
81
# File 'lib/bblib/core/mixins/delegator.rb', line 79

def delegates
  @delegates ||= ancestor_delegates
end