Sha256: 91a0fe3715ea4f145ef57c7b65f5e9a86ab06720e42921cb4a20e6426df4742d

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module ActiveRecord
  module AttributeMethods
    module Read
      def read_attribute(attr_name, &block)
        name = if self.class.attribute_alias?(attr_name)
                 # CPK
                 # self.class.attribute_alias(attr_name).to_s
                 self.class.attribute_alias(attr_name)
               else
                 # CPK
                 # attr_name.to_s
                 attr_name
               end

        primary_key = self.class.primary_key
        # CPK
        # name = primary_key if name == "id".freeze && primary_key
        name = primary_key if name == "id".freeze && primary_key && !composite?
        sync_with_transaction_state if name == primary_key
        _read_attribute(name, &block)
      end

      def _read_attribute(attr_name)
        # CPK
        if attr_name.kind_of?(Array)
          attr_name.map {|name| @attributes.fetch_value(name.to_s)}
        else
          @attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
composite_primary_keys-11.3.1 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.2.0 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.1.0 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.3 lib/composite_primary_keys/attribute_methods/read.rb