Module: ForestAdminDatasourceCustomizer::DSL::DatasourceHelpers

Included in:
ForestAdminDatasourceCustomizer::DatasourceCustomizer
Defined in:
lib/forest_admin_datasource_customizer/dsl/helpers/datasource_helpers.rb

Overview

DatasourceHelpers provides Rails-like DSL methods for datasource-level customization These methods are included in DatasourceCustomizer to provide a more idiomatic Ruby API

Instance Method Summary collapse

Instance Method Details

#chart(name, &block) ⇒ Object

Add a chart at the datasource level with a cleaner syntax

Examples:

Simple value chart

chart :total_users do
  value 1234
end

Chart with context

chart :monthly_revenue do |context|
  collection = context.datasource.get_collection('orders')
  total = calculate_revenue(collection)
  value total, previous_total
end

Parameters:

  • name (String, Symbol)

    chart name

  • block (Proc)

    chart definition block



26
27
28
29
30
31
# File 'lib/forest_admin_datasource_customizer/dsl/helpers/datasource_helpers.rb', line 26

def chart(name, &block)
  add_chart(name.to_s) do |context, result_builder|
    builder = ChartBuilder.new(context, result_builder)
    builder.instance_eval(&block)
  end
end

#collection(name, &block) ⇒ Object

Customize a collection with automatic conversion to string

Examples:

collection :users do |c|
  c.computed_field :full_name, type: 'String' { }
end

Parameters:

  • name (String, Symbol)

    collection name

  • block (Proc)

    customization block



42
43
44
# File 'lib/forest_admin_datasource_customizer/dsl/helpers/datasource_helpers.rb', line 42

def collection(name, &block)
  customize_collection(name.to_s, &block)
end

#hide_collections(*names) ⇒ Object

Hide/remove collections from Forest Admin

Examples:

hide_collections :internal_logs, :debug_info

Parameters:

  • names (Array<String, Symbol>)

    collection names to hide



52
53
54
# File 'lib/forest_admin_datasource_customizer/dsl/helpers/datasource_helpers.rb', line 52

def hide_collections(*names)
  remove_collection(*names.map(&:to_s))
end