Sha256: 9037c95625f6ac55671dd9a6608777a65f514464f844564a195e1d6e165518b0

Contents?: true

Size: 721 Bytes

Versions: 4

Compression:

Stored size: 721 Bytes

Contents

module ActiveRecord
  module AttributeMethods
    module Read
      def read_attribute(attr_name, &block)
        # CPK
        if attr_name.kind_of?(Array)
          _read_attribute(attr_name, &block)
        else
          name = attr_name.to_s
          # CPK
          name = self.class.primary_key if name == 'id'.freeze && !composite?
          _read_attribute(name, &block)
        end
      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-8.1.8 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-8.1.7 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-8.1.6 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-8.1.5 lib/composite_primary_keys/attribute_methods/read.rb