Module: AttributeInquiry::ClassMethods
- Defined in:
- lib/attribute_inquiry.rb
Overview
Defines base methods for use in selfself.included for extend
Instance Method Summary collapse
-
#has_attribute_inquiry(*keys, **options) ⇒ Object
rubocop:disable Naming/PredicateName rubocop:disable Metrics/MethodLength.
Instance Method Details
#has_attribute_inquiry(*keys, **options) ⇒ Object
rubocop:disable Naming/PredicateName rubocop:disable Metrics/MethodLength
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/attribute_inquiry.rb', line 23 def has_attribute_inquiry(*keys, **) keys.each do |key| parent_method = if [:activerecord_raw] "read_attribute(#{key})" else 'super' end class_eval( <<-DEFINITION, __FILE__, __LINE__ + 1 def #{key} ActiveSupport::StringInquirer.new( self.instance_variable_get('@#{key}') || #{parent_method} ) end DEFINITION ) end end |