Sha256: 0f216f2b3e1abe5155b7c52710aa934ecf27e0a75589ac9a339b23068b2ae811

Contents?: true

Size: 923 Bytes

Versions: 12

Compression:

Stored size: 923 Bytes

Contents

module ActiveRecord
  module AttributeMethods
    module Read
      silence_warnings do
        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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
composite_primary_keys-10.0.5 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.10 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-10.0.4 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.9 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-10.0.3 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-10.0.2 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-10.0.1 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.8 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-10.0.0 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.7 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.6 lib/composite_primary_keys/attribute_methods/read.rb
composite_primary_keys-9.0.5 lib/composite_primary_keys/attribute_methods/read.rb