class ActiveRecord::AttributeMethods::AttributeMethodCache - activerecord-4.2.5.2 Documentation

# class ActiveRecord::AttributeMethods::AttributeMethodCache

### Public Class Methods

new() click to toggle source

    # File lib/active_record/attribute_methods.rb, line 38
    def initialize
      @module = Module.new
      @method_cache = ThreadSafe::Cache.new
    end

### Public Instance Methods

[](name) click to toggle source

    # File lib/active_record/attribute_methods.rb, line 43
    def [](name)
      @method_cache.compute_if_absent(name) do
        safe_name = name.unpack('h*').first
        temp_method = "__temp__#{safe_name}"
        ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
        @module.module_eval method_body(temp_method, safe_name), __FILE__, __LINE__
        @module.instance_method temp_method
      end
    end

### Private Instance Methods

method_body(method_name, const_name) click to toggle source

Override this method in the subclasses for method body.

    # File lib/active_record/attribute_methods.rb, line 56
    def method_body(method_name, const_name)
      raise NotImplementedError, "Subclasses must implement a method_body(method_name, const_name) method."
    end