Sha256: 8b3db557b9c930ae50ecd32db00472c45daec29451d96e00d0fdc55bfa44025f

Contents?: true

Size: 736 Bytes

Versions: 1

Compression:

Stored size: 736 Bytes

Contents

class Report < ActiveRecord::Base
  serialize :used_columns
  validates_presence_of :used_columns

  def available_columns
    ::ReportUi.reportable_models.inject({}) do |result, model|
      result.merge(model => model.columns.inject({}) do |model_attrs, attr|
        model_attrs.merge(attr.name.to_sym => ((self.used_columns || []).include?("#{model.name}##{attr.name}")))
      end)
    end
  end

  def query
    case type
    when 'ruby'
      eval(code)
    when 'sql'
      Report.find_by_sql(code)
    end
  end


  def humanized_column_names
    column_names.map(&:humanize)
  end

  def column_names
    used_columns.map do |full_col|
      full_col.scan(/#(.*)/).flatten[0]
    end
  end

  def data
    eval code
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
report_ui-0.0.1.alpha lib/app/models/report.rb