Class: SafeFinder::ClassWrapper
- Inherits:
-
Object
- Object
- SafeFinder::ClassWrapper
- Defined in:
- lib/safe_finder/class_wrapper.rb
Instance Attribute Summary collapse
-
#wrapped_class ⇒ Object
readonly
Returns the value of attribute wrapped_class.
Instance Method Summary collapse
-
#initialize(target_class) ⇒ ClassWrapper
constructor
A new instance of ClassWrapper.
- #method_missing(name, *arguments, &block) ⇒ Object
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_class ⇒ Object (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 |