Class: SafeFinder::ClassWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_finder/class_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_class) ⇒ ClassWrapper

Returns a new instance of ClassWrapper.



5
6
7
# File 'lib/safe_finder/class_wrapper.rb', line 5

def initialize(target_class)
  @wrapped_class = target_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/safe_finder/class_wrapper.rb', line 9

def method_missing(name, *arguments, &block)
  result = wrapped_class.send(name, *arguments, &block)
  result.nil? ? wrapped_class.null_object : result
rescue ActiveRecord::RecordNotFound
  wrapped_class.null_object
end

Instance Attribute Details

#wrapped_classObject (readonly)

Returns the value of attribute wrapped_class.



3
4
5
# File 'lib/safe_finder/class_wrapper.rb', line 3

def wrapped_class
  @wrapped_class
end