Module: Bondo

Defined in:
lib/bondo.rb,
lib/bondo/version.rb

Overview

Usage

require 'bondo'

class Bar
  def start
  end
end

class Baz
  def eject
  end
end

class Foo < SomeClass
  include Bondo

  def initialize
    bondo_add Bar.new
    bondo_add Baz.new
  end
end

f = Foo.new
f.stop
f.eject

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



53
54
55
56
57
58
59
60
# File 'lib/bondo.rb', line 53

def method_missing(symbol_or_string, *args, &block)
  if respond_to_missing?(symbol_or_string, false)
    bondo_children.map { |x|
      return x.send(symbol_or_string, *args, &block) if x.respond_to? symbol_or_string
    }
  end
  super
end

Instance Method Details

#bondo_add(*children) ⇒ Object



33
34
35
# File 'lib/bondo.rb', line 33

def bondo_add(*children)
  children.each { |child| bondo_children.unshift child } unless bondo_has_all?(*children)
end

#bondo_childrenObject



29
30
31
# File 'lib/bondo.rb', line 29

def bondo_children
  @bondo_children ||= []
end

#bondo_has?(child) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bondo.rb', line 41

def bondo_has?(child)
  bondo_children.include? child
end

#bondo_has_all?(*children) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bondo.rb', line 37

def bondo_has_all?(*children)
  children.all? { |child| bondo_has? child }
end

#bondo_remove(child) ⇒ Object



45
46
47
# File 'lib/bondo.rb', line 45

def bondo_remove(child)
  bondo_children.delete child if bondo_has? child
end

#respond_to_missing?(symbol_or_string, include_all) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bondo.rb', line 49

def respond_to_missing?(symbol_or_string, include_all)
  bondo_children.map { |x| x.respond_to? symbol_or_string, include_all }.any? || super
end