Exception: ImplementInSubclass

Inherits:
StandardError
  • Object
show all
Defined in:
app/services/implement_in_subclass.rb

Overview

To force an interface raise this error:

raise ImplementInSubclass.new(self)

to raise an error with a nice message

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ImplementInSubclass

Returns a new instance of ImplementInSubclass.



5
6
7
8
9
# File 'app/services/implement_in_subclass.rb', line 5

def initialize(klass)
  @calling_method = caller_locations(2,1)[0]
  @concerning_class = klass.is_a?(Class) ? klass : klass.class # can be called from instance or class
  super
end

Instance Method Details

#messageObject



15
16
17
# File 'app/services/implement_in_subclass.rb', line 15

def message
  "Implement method: #{method_to_be_implemented} in a subclass of #{@concerning_class.name}"
end

#method_to_be_implementedObject



11
12
13
# File 'app/services/implement_in_subclass.rb', line 11

def method_to_be_implemented
  @calling_method.label
end