marat.adiyatullin
marat.adiyatullin

Reputation: 63

DSL configuration within activerecord model in Rails 3

I want to build reports for some database data. I store report's settings in database through activerecord models, but I don't want that, I want to write something like

class Department < ActiveRecord::Base
    ...
    report do
        name   "Total Sales by Departments"
        method :name

        report_field do
            name     "Total Sales"
            action   :sum
            relation "Sales"
            method   :spent
        end

        report_field do
            name     "Average Sales"
            action   :avg
            relation "Sales"
            method   :spent
        end
    end
end

Can someone please tell me how this is possible to do and what should I read, maybe some examples of other things that are similar to my problem?

Upvotes: 3

Views: 242

Answers (1)

Andy Waite
Andy Waite

Reputation: 11076

I would start by reading about Class Macros.

Upvotes: 4

Related Questions