Class: Bossy::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/bossy/interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, required_methods) ⇒ Interface

Returns a new instance of Interface.



5
6
7
8
9
# File 'lib/bossy/interface.rb', line 5

def initialize(klass, required_methods)
  @klass = klass
  @interface_methods = []
  add_required_methods(required_methods)
end

Instance Attribute Details

#interface_methodsObject

Returns the value of attribute interface_methods.



3
4
5
# File 'lib/bossy/interface.rb', line 3

def interface_methods
  @interface_methods
end

#klassObject

Returns the value of attribute klass.



3
4
5
# File 'lib/bossy/interface.rb', line 3

def klass
  @klass
end

Instance Method Details

#add_required_methods(m) ⇒ Object



21
22
23
# File 'lib/bossy/interface.rb', line 21

def add_required_methods(m)
  @interface_methods += m
end


32
33
34
# File 'lib/bossy/interface.rb', line 32

def print
  puts to_s
end

#to_sObject



25
26
27
28
29
30
# File 'lib/bossy/interface.rb', line 25

def to_s
  bullet = "\u279E".encode
  s  = "Interface for #{@klass}\n"
  s += interface_methods.map{|m| "#{bullet} #{m}" }.join("\n")
  return s
end

#validate!Object



11
12
13
14
15
16
17
18
19
# File 'lib/bossy/interface.rb', line 11

def validate!
  interface_methods.each do |method_signature|
    unless class_has_method?(klass, method_signature.name)
      raise Bossy::Errors::MethodMissing, "Please define #{klass}##{method_signature.name} with the signature:\n\n#{method_signature}\n\n"
    end
  end

  return true
end