Module: AttributeInquiry::ClassMethods

Defined in:
lib/attribute_inquiry.rb

Overview

Defines base methods for use in selfself.included for extend

Instance Method Summary collapse

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, **options)
  keys.each do |key|
    parent_method = if options[:activerecord_raw]
                      "read_attribute(#{key})"
                    else
                      'super'
                    end

    class_eval(
      "        def \#{key}\n          ActiveSupport::StringInquirer.new(\n            self.instance_variable_get('@\#{key}') ||\n            \#{parent_method}\n          )\n        end\n      DEFINITION\n    )\n  end\nend\n", __FILE__, __LINE__ + 1