Sha256: db09bda8728b1f39ae9bd6a7b757c2e4ae85e0d6c16b8b078c48e44a0db6d6a2

Contents?: true

Size: 845 Bytes

Versions: 8

Compression:

Stored size: 845 Bytes

Contents

module ActiveRecord
  module AttributeMethods
    module Read
      def read_attribute(attr_name, &block)
        # CPK
        if attr_name.kind_of?(Array) || attr_name.to_s == 'id'.freeze && @attributes.key?('id')
          _read_attribute(attr_name, &block)
        else
          name = attr_name.to_s
          # CPK
          #name = self.class.primary_key if name == 'id'.freeze
          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

8 entries across 8 versions & 1 rubygems

Version Path
composite_primary_keys-11.0.2 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.1 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0.rc1 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0.beta4 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0.beta3 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0.beta2 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-11.0.0.beta1 lib/composite_primary_keys/attribute_methods/read.rb