ankane / blazer

Business intelligence made simple
MIT License
4.5k stars 471 forks source link

Using after_initialize in engine #471

Open juanmanuelramallo opened 5 months ago

juanmanuelramallo commented 5 months ago

Allows users to execute ruby code that consumes classes from app/models or any other portion of their app.

This is particularly helpful for creating smart columns for AR enums. i.e.:

# app/models/account.rb
class Account < ApplicationRecord
  enum state: [:pending, :setup, :succeded, :failed]
end

# config/blazer.yml
data_sources:
  main:
    smart_columns:
      account_state: <%= Account.states.to_h {|k,v| [v, k.titleize]}.to_json %>

Without this change, initialization fails with error "uninitialized constant Account (NameError)".