Sha256: f10bbe98359b0f6455b0f0ba528df48bca47e29412bc578d7cce2928473c482c
Contents?: true
Size: 1.15 KB
Versions: 6
Compression:
Stored size: 1.15 KB
Contents
module Datatable module ActiveRecordDSL def self.included(base) base.extend ClassMethods end module ClassMethods def relation @relation end def relation=(arg) @relation = arg end def set_model(model) @model = model @relation = model end def current_model @inner_model || @model end def column(c, options={}) raise "set_model not called on #{self.name}" unless @model @columns ||= ActiveSupport::OrderedHash.new column_hash = options unless column_hash[:type] column_hash[:type] = current_model.columns.detect{ |col| col.name == c.to_s}.type end @columns["#{current_model.table_name}.#{c}"] = column_hash @relation= @relation.select(current_model.arel_table[c]) end # TODO: Change to joins to match arel def join(association, &block) @inner_model = current_model.reflect_on_association(association).klass @relation = @relation.joins(association) instance_eval(&block) if block_given? @inner_model = nil end end end end
Version data entries
6 entries across 6 versions & 1 rubygems