Class: Monolens::Type::Responding

Inherits:
Object
  • Object
show all
Includes:
ErrorHandling
Defined in:
lib/monolens/type/responding.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorHandling

#fail!

Constructor Details

#initialize(messages) ⇒ Responding

Returns a new instance of Responding.



6
7
8
# File 'lib/monolens/type/responding.rb', line 6

def initialize(messages)
  @messages = messages
end

Class Method Details

.to(*messages) ⇒ Object



10
11
12
# File 'lib/monolens/type/responding.rb', line 10

def self.to(*messages)
  new(messages)
end

Instance Method Details

#===(instance) ⇒ Object



20
21
22
# File 'lib/monolens/type/responding.rb', line 20

def ===(instance)
  @messages.all?{|m| instance.respond_to?(m) }
end

#dress(instance, registry, &block) ⇒ Object



14
15
16
17
18
# File 'lib/monolens/type/responding.rb', line 14

def dress(instance, registry, &block)
  fail!("Invalid #{instance}", &block) unless self === instance

  instance
end