Sha256: 4534c82c98794fcee0224b751d0d0ce2b97527dbc51109a2371b13e91967a466

Contents?: true

Size: 913 Bytes

Versions: 9

Compression:

Stored size: 913 Bytes

Contents

module QueryReport
  module Record
    attr_accessor :query

    def model_class
      query.klass
    end

    def filtered_query
      apply
      @filtered_query
    end

    def paginated_query
      apply
      @paginated_query
    end

    def search
      apply
      @search
    end

    def apply
      @filtered_query ||= apply_filters(query.clone, @params)
      @paginated_query ||= apply_pagination(@filtered_query, @params)
    end

    def records
      @records ||= map_record(paginated_query, true)
    end

    def all_records
      @all_records ||= map_record(filtered_query, false)
    end

    def map_record(query, render_from_view)
      @columns = @columns.delete_if { |col| col.only_on_web? } unless render_from_view

      query.map do |record|
        array = @columns.collect { |column| [column.humanize, column.value(record)] }
        Hash[*array.flatten]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
query_report-1.0.8 lib/query_report/record.rb
query_report-1.0.7 lib/query_report/record.rb
query_report-1.0.6 lib/query_report/record.rb
query_report-1.0.5 lib/query_report/record.rb
query_report-1.0.4 lib/query_report/record.rb
query_report-1.0.3 lib/query_report/record.rb
query_report-1.0.2 lib/query_report/record.rb
query_report-1.0.1 lib/query_report/record.rb
query_report-1.0.0 lib/query_report/record.rb