Module: OptAR::MethodFinderHelper
- Included in:
- OAR
- Defined in:
- lib/opt_ar/helpers/method_finder_helper.rb
Overview
Methods for handling all attributes read
Constant Summary collapse
- ID_STRING =
'id'.freeze
- WARN_MSG =
'WARNING :: Trying to access attr that was not requested'.freeze
- DEFAULT_DATE_TIME_ATTRIBUTES =
%i[created_at updated_at].freeze
- DATE_TIME_CONST_KEY =
'DATE_TIME_ATTRIBUTES'.freeze
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
Checks for attribute from the attributes hash and returns if found
Overriding to avoid attributes misses from causing an error It just throws a warning and proceeds with fetching the actual
ActiveRecord object,to check for it's response to the method
defined by name method_name
Provided only as a fallback for the worst case scenario. Avoid calling
methods on the instance, for attribute that was not requested initially
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/opt_ar/helpers/method_finder_helper.rb', line 26 def method_missing(method_name, *args) method_name = method_name.to_sym return read_from_attributes(method_name) if @attributes.key?(method_name) raise OptAR::Errors::MissingPrimaryKeyError if primary_key?(method_name) raise OptAR::Errors::MutationNotAllowedError if assign?(method_name) OptAR::Logger.log("#{WARN_MSG} :: #{method_name}", :warn) load_ar_object @klass_object ? @klass_object.send(method_name, *args) : super end |