Sha256: eb6cecdb1b7223facb5c3841335c45202aff804ab9ab5e99e00207d2355a57f4

Contents?: true

Size: 681 Bytes

Versions: 42

Compression:

Stored size: 681 Bytes

Contents

module ActiveRecord
  class Base
    # Specifies that values of the given attributes should be returned
    # as symbols. The table column should be created of type string.
    def self.symbolize (*attr_names)
      attr_names.each do |attr_name|
        attr_name = attr_name.to_s
        class_eval("def #{attr_name}; read_and_symbolize_attribute('#{attr_name}'); end")
        class_eval("def #{attr_name}= (value); write_attribute('#{attr_name}', value.to_s); end")
      end
    end
    # Return an attribute's value as a symbol
    def read_and_symbolize_attribute (attr_name)
      value = read_attribute(attr_name)
      value.blank? ? nil : value.to_sym
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
virgo-0.3.17 config/initializers/active_record_symbolize.rb
virgo-0.3.16 config/initializers/active_record_symbolize.rb
virgo-0.3.15 config/initializers/active_record_symbolize.rb
virgo-0.3.14 config/initializers/active_record_symbolize.rb
virgo-0.3.13 config/initializers/active_record_symbolize.rb
virgo-0.3.12 config/initializers/active_record_symbolize.rb
virgo-0.3.11 config/initializers/active_record_symbolize.rb
virgo-0.3.10 config/initializers/active_record_symbolize.rb
virgo-0.3.9 config/initializers/active_record_symbolize.rb
virgo-0.3.8 config/initializers/active_record_symbolize.rb
virgo-0.3.7 config/initializers/active_record_symbolize.rb
virgo-0.3.6 config/initializers/active_record_symbolize.rb
virgo-0.3.4 config/initializers/active_record_symbolize.rb
virgo-0.3.3 config/initializers/active_record_symbolize.rb
virgo-0.3.2 config/initializers/active_record_symbolize.rb
virgo-0.3.1 config/initializers/active_record_symbolize.rb
virgo-0.3 config/initializers/active_record_symbolize.rb
virgo-0.2.9 config/initializers/active_record_symbolize.rb
virgo-0.2.8 config/initializers/active_record_symbolize.rb
virgo-0.2.7 config/initializers/active_record_symbolize.rb