require 'lazy_high_charts/engine'
require 'rails_admin_charts/engine'

module RailsAdminCharts
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def total_records_since(since = 30.days.ago)
      totals, before_count = self.group('DATE(created_at)').count, self.where('created_at < ?', since.to_date).count
      (since.to_date..Date.today).each_with_object([]) { |day, a| a << (a.last || before_count) + (totals[day] || 0) }
    end

    def delta_records_since(since = 30.days.ago)
      deltas = self.group('DATE(created_at)').count
      (since.to_date..Date.today).map { |date| deltas[date] || 0 }
    end

    def graph_data since=30.days.ago
      [
          {
              name: model_name.pluralize,
              pointInterval: 1.day * 1000,
              pointStart: since.to_i * 1000,
              data: self.total_records_since(since)
          }
      ]
    end
  end
end

require 'rails_admin_charts/rails_admin/config/actions/charts'
require 'lazy_high_charts/engine'
require 'rails_admin_charts/engine'

module RailsAdminCharts
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def total_records_since(since = 30.days.ago)
      totals, before_count = self.group('DATE(created_at)').count, self.where('created_at < ?', since.to_date).count
      (since.to_date..Date.today).each_with_object([]) { |day, a| a << (a.last || before_count) + (totals[day] || 0) }
    end

    def delta_records_since(since = 30.days.ago)
      deltas = self.group('DATE(created_at)').count
      (since.to_date..Date.today).map { |date| deltas[date] || 0 }
    end

    def graph_data since=30.days.ago
      [
          {
              name: model_name.plural,
              pointInterval: 1.day * 1000,
              pointStart: since.to_i * 1000,
              data: self.total_records_since(since)
          }
      ]
    end
  end
end

require 'rails_admin_charts/rails_admin/config/actions/charts'

Use `plural` instead of `pluralize` with ModelName instance in `graph_data`
Use `plural` instead of `pluralize` with ModelName instance in `graph_data`

Fixes Rails 4, rails_admin 0.5.0 'undefined method `pluralize' for #<ActiveModel::Name:0x007f93a0175990>'