Module: ActiveRecord::AttributeMethods::Read
- Defined in:
- lib/composite_primary_keys/attribute_methods/read.rb
Instance Method Summary collapse
Instance Method Details
#_read_attribute(attr_name) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/composite_primary_keys/attribute_methods/read.rb', line 17 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 |
#read_attribute(attr_name, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/composite_primary_keys/attribute_methods/read.rb', line 4 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 |