Sha256: e1b26c7effa9b933fd94fb21926f365d83033a7e5843a4c24296f123340a6fd7

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

module Dataset
  module Record # :nodoc:
    
    # A mechanism to cache information about an ActiveRecord class to speed
    # things up a bit for insertions, finds, and method generation.
    class Meta # :nodoc:
      attr_reader :class_name, :columns, :record_class, :table_name
      
      def initialize(record_class)
        @record_class     = record_class
        @class_name       = record_class.name
        @table_name       = record_class.table_name
        @columns          = record_class.columns
      end
      
      def timestamp_columns
        @timestamp_columns ||= begin
          timestamps = %w(created_at created_on updated_at updated_on)
          columns.select do |column|
            timestamps.include?(column.name)
          end
        end
      end
      
      def id_reader
        @id_reader ||= begin
          reader = ActiveRecord::Base.pluralize_table_names ? table_name.singularize : table_name
          "#{reader}_id".to_sym
        end
      end
      
      def record_reader
        @record_reader ||= table_name.to_sym
      end
      
      def to_s
        "#<RecordMeta: #{table_name}>"
      end
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-0.7.2 vendor/plugins/dataset/lib/dataset/record/meta.rb
radiant-0.7.0 vendor/plugins/dataset/lib/dataset/record/meta.rb
radiant-0.7.1 vendor/plugins/dataset/lib/dataset/record/meta.rb