Module: Casting

Defined in:
lib/casting.rb,
lib/casting/null.rb,
lib/casting/client.rb,
lib/casting/version.rb,
lib/casting/delegation.rb,
lib/casting/super_delegate.rb,
lib/casting/method_consolidator.rb,
lib/casting/prepared_delegation.rb,
lib/casting/missing_method_client.rb,
lib/casting/missing_method_client_class.rb

Defined Under Namespace

Modules: Blank, Client, Empty, MethodConsolidator, MissingMethodClient, MissingMethodClientClass, Null, SuperDelegate Classes: Delegation, InvalidAttendant, InvalidClientError, MissingAttendant, PreparedDelegation

Constant Summary collapse

VERSION =
'0.7.1'

Class Method Summary collapse

Class Method Details

.cast_object(object, mod) ⇒ Object

Raises:


20
21
22
23
24
# File 'lib/casting.rb', line 20

def self.cast_object(object, mod)
  raise InvalidClientError.new unless object.respond_to?(:cast_as)

  object.cast_as(mod)
end

.delegating(assignments) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'lib/casting.rb', line 9

def self.delegating(assignments)
  assignments.each do |object, mod|
    cast_object(object, mod)
  end
  yield
ensure
  assignments.each do |object, mod|
    uncast_object(object)
  end
end

.uncast_object(object) ⇒ Object


26
27
28
29
30
# File 'lib/casting.rb', line 26

def self.uncast_object(object)
  return unless object.respond_to?(:uncast)

  object.uncast
end