Sha256: 4472172f08b1ea65d8b597967c63929758556ccc8e6d7c58bc7ebf90b0c62700
Contents?: true
Size: 1.09 KB
Versions: 3
Compression:
Stored size: 1.09 KB
Contents
module Datatable module ActiveRecordDSL def self.included(base) base.extend ClassMethods end module ClassMethods def relation @relation 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 = {} column_hash[:type] = current_model.columns.detect{ |col| col.name == c.to_s}.type column_hash[:link_to] = options[:link_to] @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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
datatable-0.1.1alpha4 | lib/datatable/active_record_dsl.rb |
datatable-0.1.1alpha1 | lib/datatable/active_record_dsl.rb |
datatable-0.1.0alpha2 | lib/datatable/active_record_dsl.rb |