Class: Brick::Config

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/brick/config.rb

Overview

Global configuration affecting all threads. Some thread-specific configuration can be found in ‘brick.rb`, others in `controller.rb`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



14
15
16
17
18
19
20
21
# File 'lib/brick/config.rb', line 14

def initialize
  # Variables which affect all threads, whose access is synchronized.
  @mutex = Mutex.new
  @enabled = true

  # Variables which affect all threads, whose access is *not* synchronized.
  @serializer = Brick::Serializers::YAML
end

Instance Attribute Details

#association_reify_error_behaviourObject

Returns the value of attribute association_reify_error_behaviour.



11
12
13
# File 'lib/brick/config.rb', line 11

def association_reify_error_behaviour
  @association_reify_error_behaviour
end

#object_changes_adapterObject

Returns the value of attribute object_changes_adapter.



11
12
13
# File 'lib/brick/config.rb', line 11

def object_changes_adapter
  @object_changes_adapter
end

#root_modelObject

Returns the value of attribute root_model.



11
12
13
# File 'lib/brick/config.rb', line 11

def root_model
  @root_model
end

#serializerObject

Returns the value of attribute serializer.



11
12
13
# File 'lib/brick/config.rb', line 11

def serializer
  @serializer
end

#version_limitObject

Returns the value of attribute version_limit.



11
12
13
# File 'lib/brick/config.rb', line 11

def version_limit
  @version_limit
end

Instance Method Details

#acts_as_list_colsObject



432
433
434
# File 'lib/brick/config.rb', line 432

def acts_as_list_cols
  @mutex.synchronize { @acts_as_list || {} }
end

#acts_as_list_cols=(position_cols) ⇒ Object

Get something like:

{ 'on_call_list' => { _brick_default: [:last_name, :first_name] } }
{ 'on_call_list' => { _brick_default: :sequence } }


439
440
441
442
443
# File 'lib/brick/config.rb', line 439

def acts_as_list_cols=(position_cols)
  @mutex.synchronize do
    @acts_as_list ||= position_cols
  end
end

#add_orphansObject

Add a special page to show references to non-existent records (“orphans”)



496
497
498
# File 'lib/brick/config.rb', line 496

def add_orphans
  true
end

#add_searchObject

Add search page for general Elasticsearch / Opensearch querying



486
487
488
# File 'lib/brick/config.rb', line 486

def add_search
  true
end

#add_statusObject

Add status page showing all resources and what files have been built out for them



491
492
493
# File 'lib/brick/config.rb', line 491

def add_status
  true
end

#additional_referencesObject

Additional table associations to use (Think of these as virtual foreign keys perhaps)



159
160
161
# File 'lib/brick/config.rb', line 159

def additional_references
  @mutex.synchronize { @additional_references }
end

#additional_references=(references) ⇒ Object



163
164
165
# File 'lib/brick/config.rb', line 163

def additional_references=(references)
  @mutex.synchronize { @additional_references = references }
end

#always_load_fieldsObject



469
470
471
# File 'lib/brick/config.rb', line 469

def always_load_fields
  @mutex.synchronize { @always_load_fields || {} }
end

#always_load_fields=(field_set) ⇒ Object



473
474
475
# File 'lib/brick/config.rb', line 473

def always_load_fields=(field_set)
  @mutex.synchronize { @always_load_fields = field_set }
end

#api_add_view_prefixObject



150
151
152
# File 'lib/brick/config.rb', line 150

def api_add_view_prefix
  @mutex.synchronize { @api_add_view_prefix || @api_view_prefix }
end

#api_add_view_prefix=(view_prefix) ⇒ Object



154
155
156
# File 'lib/brick/config.rb', line 154

def api_add_view_prefix=(view_prefix)
  @mutex.synchronize { @api_add_view_prefix = view_prefix }
end

#api_column_renamingObject

Allows you to rename and exclude columns either specific to a given API version, or generally for a database object name



125
126
127
# File 'lib/brick/config.rb', line 125

def api_column_renaming
  @mutex.synchronize { @api_column_renaming }
end

#api_column_renaming=(renames) ⇒ Object



129
130
131
# File 'lib/brick/config.rb', line 129

def api_column_renaming=(renames)
  @mutex.synchronize { @api_column_renaming = renames }
end

#api_filterObject



106
107
108
# File 'lib/brick/config.rb', line 106

def api_filter
  @mutex.synchronize { @api_filter }
end

#api_filter=(proc) ⇒ Object



110
111
112
# File 'lib/brick/config.rb', line 110

def api_filter=(proc)
  @mutex.synchronize { @api_filter = proc }
end

#api_remove_view_prefixObject



142
143
144
# File 'lib/brick/config.rb', line 142

def api_remove_view_prefix
  @mutex.synchronize { @api_remove_view_prefix || @api_view_prefix }
end

#api_remove_view_prefix=(view_prefix) ⇒ Object



146
147
148
# File 'lib/brick/config.rb', line 146

def api_remove_view_prefix=(view_prefix)
  @mutex.synchronize { @api_remove_view_prefix = view_prefix }
end

#api_rootsObject



98
99
100
# File 'lib/brick/config.rb', line 98

def api_roots
  @mutex.synchronize { @api_roots || ["/api/v1/"] }
end

#api_roots=(path) ⇒ Object



102
103
104
# File 'lib/brick/config.rb', line 102

def api_roots=(path)
  @mutex.synchronize { @api_roots = path }
end

#api_view_prefixObject

All the view prefix things



134
135
136
# File 'lib/brick/config.rb', line 134

def api_view_prefix
  @mutex.synchronize { @api_view_prefix }
end

#api_view_prefix=(view_prefix) ⇒ Object



138
139
140
# File 'lib/brick/config.rb', line 138

def api_view_prefix=(view_prefix)
  @mutex.synchronize { @api_view_prefix = view_prefix }
end

#controllers_inherit_fromObject



384
385
386
# File 'lib/brick/config.rb', line 384

def controllers_inherit_from
  @mutex.synchronize { @controllers_inherit_from }
end

#controllers_inherit_from=(value) ⇒ Object



388
389
390
# File 'lib/brick/config.rb', line 388

def controllers_inherit_from=(value)
  @mutex.synchronize { @controllers_inherit_from = value }
end

#custom_columnsObject

Custom columns to add to a table, minimally defined with a name and DSL string



177
178
179
# File 'lib/brick/config.rb', line 177

def custom_columns
  @mutex.synchronize { @custom_columns }
end

#custom_columns=(cust_cols) ⇒ Object



181
182
183
# File 'lib/brick/config.rb', line 181

def custom_columns=(cust_cols)
  @mutex.synchronize { @custom_columns = cust_cols }
end

#default_route_fallbackObject



352
353
354
# File 'lib/brick/config.rb', line 352

def default_route_fallback
  @mutex.synchronize { @default_route_fallback }
end

#default_route_fallback=(resource_name) ⇒ Object



356
357
358
# File 'lib/brick/config.rb', line 356

def default_route_fallback=(resource_name)
  @mutex.synchronize { @default_route_fallback = resource_name }
end

#defer_references_for_generationObject

References to disregard when auto-building migrations, models, and seeds



168
169
170
# File 'lib/brick/config.rb', line 168

def defer_references_for_generation
  @mutex.synchronize { @defer_references_for_generation }
end

#defer_references_for_generation=(drfg) ⇒ Object



172
173
174
# File 'lib/brick/config.rb', line 172

def defer_references_for_generation=(drfg)
  @mutex.synchronize { @defer_references_for_generation = drfg }
end

#enable_apiObject



90
91
92
# File 'lib/brick/config.rb', line 90

def enable_api
  @mutex.synchronize { @enable_api }
end

#enable_api=(enable) ⇒ Object



94
95
96
# File 'lib/brick/config.rb', line 94

def enable_api=(enable)
  @mutex.synchronize { @enable_api = enable }
end

#enable_controllersObject

Indicates whether Brick controllers are on or off. Default: true.



61
62
63
64
# File 'lib/brick/config.rb', line 61

def enable_controllers
  brick_mode = mode
  @mutex.synchronize { brick_mode == :on && (@enable_controllers.nil? || @enable_controllers) }
end

#enable_controllers=(enable) ⇒ Object



66
67
68
# File 'lib/brick/config.rb', line 66

def enable_controllers=(enable)
  @mutex.synchronize { @enable_controllers = enable }
end

#enable_modelsObject

Indicates whether Brick models are on or off. Default: true.



51
52
53
54
# File 'lib/brick/config.rb', line 51

def enable_models
  brick_mode = mode
  @mutex.synchronize { brick_mode == :on && (@enable_models.nil? || @enable_models) }
end

#enable_models=(enable) ⇒ Object



56
57
58
# File 'lib/brick/config.rb', line 56

def enable_models=(enable)
  @mutex.synchronize { @enable_models = enable }
end

#enable_routesObject

Indicates whether Brick routes are on or off. Default: true.



81
82
83
84
# File 'lib/brick/config.rb', line 81

def enable_routes
  brick_mode = mode
  @mutex.synchronize { brick_mode == :on && (@enable_routes.nil? || @enable_routes) }
end

#enable_routes=(enable) ⇒ Object



86
87
88
# File 'lib/brick/config.rb', line 86

def enable_routes=(enable)
  @mutex.synchronize { @enable_routes = enable }
end

#enable_viewsObject

Indicates whether Brick views are on or off. Default: true.



71
72
73
74
# File 'lib/brick/config.rb', line 71

def enable_views
  brick_mode = mode
  @mutex.synchronize { brick_mode == :on && (@enable_views.nil? || @enable_views) }
end

#enable_views=(enable) ⇒ Object



76
77
78
# File 'lib/brick/config.rb', line 76

def enable_views=(enable)
  @mutex.synchronize { @enable_views = enable }
end

#erd_show_columnsObject



306
307
308
# File 'lib/brick/config.rb', line 306

def erd_show_columns
  @mutex.synchronize { @erd_show_columns ||= [] }
end

#erd_show_columns=(descrips) ⇒ Object



310
311
312
# File 'lib/brick/config.rb', line 310

def erd_show_columns=(descrips)
  @mutex.synchronize { @erd_show_columns = descrips }
end

#exclude_hmsObject

Skip creating a has_many association for these



186
187
188
# File 'lib/brick/config.rb', line 186

def exclude_hms
  @mutex.synchronize { @exclude_hms }
end

#exclude_hms=(skips) ⇒ Object



190
191
192
# File 'lib/brick/config.rb', line 190

def exclude_hms=(skips)
  @mutex.synchronize { @exclude_hms = skips }
end

#exclude_tablesObject



368
369
370
# File 'lib/brick/config.rb', line 368

def exclude_tables
  @mutex.synchronize { @exclude_tables || [] }
end

#exclude_tables=(value) ⇒ Object



372
373
374
# File 'lib/brick/config.rb', line 372

def exclude_tables=(value)
  @mutex.synchronize { @exclude_tables = value }
end

#has_onesObject

Associations to treat as a has_one



209
210
211
# File 'lib/brick/config.rb', line 209

def has_ones
  @mutex.synchronize { @has_ones }
end

#has_ones=(hos) ⇒ Object



213
214
215
# File 'lib/brick/config.rb', line 213

def has_ones=(hos)
  @mutex.synchronize { @has_ones = hos }
end

#hmtsObject

Associations for which to auto-create a has_many _, through: _



227
228
229
# File 'lib/brick/config.rb', line 227

def hmts
  @mutex.synchronize { @hmts }
end

#hmts=(assocs) ⇒ Object



231
232
233
# File 'lib/brick/config.rb', line 231

def hmts=(assocs)
  @mutex.synchronize { @hmts = assocs }
end

#ignore_migration_fksObject



477
478
479
# File 'lib/brick/config.rb', line 477

def ignore_migration_fks
  @mutex.synchronize { @ignore_migration_fks || [] }
end

#ignore_migration_fks=(relations) ⇒ Object



481
482
483
# File 'lib/brick/config.rb', line 481

def ignore_migration_fks=(relations)
  @mutex.synchronize { @ignore_migration_fks = relations }
end

#json_columnsObject



270
271
272
# File 'lib/brick/config.rb', line 270

def json_columns
  @mutex.synchronize { @json_columns ||= {} }
end

#json_columns=(cols) ⇒ Object



274
275
276
# File 'lib/brick/config.rb', line 274

def json_columns=(cols)
  @mutex.synchronize { @json_columns = cols }
end

#licenseObject



500
501
502
# File 'lib/brick/config.rb', line 500

def license
  @mutex.synchronize { @license }
end

#license=(key) ⇒ Object



504
505
506
# File 'lib/brick/config.rb', line 504

def license=(key)
  @mutex.synchronize { @license = key }
end

#limit_carrierwaveObject

Restrict all Carrierwave images when set to true, or limit to the first n number if set to an Integer



280
281
282
283
284
# File 'lib/brick/config.rb', line 280

def limit_carrierwave
  # When not set then by default just do a max of 50 images so that
  # a grid of say 1000 things won't bring the page to its knees
  @mutex.synchronize { @limit_carrierwave ||= 50 }
end

#limit_carrierwave=(num) ⇒ Object



286
287
288
# File 'lib/brick/config.rb', line 286

def limit_carrierwave=(num)
  @mutex.synchronize { @limit_carrierwave = num }
end

#metadata_columnsObject



445
446
447
# File 'lib/brick/config.rb', line 445

def 
  @mutex.synchronize { @metadata_columns ||= ['created_at', 'updated_at', 'deleted_at'] }
end

#metadata_columns=(columns) ⇒ Object



449
450
451
# File 'lib/brick/config.rb', line 449

def (columns)
  @mutex.synchronize { @metadata_columns = columns }
end

#modeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/brick/config.rb', line 23

def mode
  rails_env = Object.const_defined?('Rails') && ::Rails.env
  @mutex.synchronize do
    case @brick_mode
    when nil, :development
      (rails_env == 'development' || ENV.key?('BRICK')) ? :on : nil
    when :diag_env
      ENV.key?('BRICK') ? :on : nil
    else
      @brick_mode
    end
  end
end

#mode=(setting) ⇒ Object



37
38
39
# File 'lib/brick/config.rb', line 37

def mode=(setting)
  @mutex.synchronize { @brick_mode = setting unless @brick_mode == :on }
end

#model_descripsObject



298
299
300
# File 'lib/brick/config.rb', line 298

def model_descrips
  @mutex.synchronize { @model_descrips ||= {} }
end

#model_descrips=(descrips) ⇒ Object



302
303
304
# File 'lib/brick/config.rb', line 302

def model_descrips=(descrips)
  @mutex.synchronize { @model_descrips = descrips }
end

#models_inherit_fromObject



376
377
378
# File 'lib/brick/config.rb', line 376

def models_inherit_from
  @mutex.synchronize { @models_inherit_from }
end

#models_inherit_from=(value) ⇒ Object



380
381
382
# File 'lib/brick/config.rb', line 380

def models_inherit_from=(value)
  @mutex.synchronize { @models_inherit_from = value }
end

#nested_attributesObject

Associations upon which to add #accepts_nested_attributes_for logic



218
219
220
# File 'lib/brick/config.rb', line 218

def nested_attributes
  @mutex.synchronize { @nested_attributes }
end

#nested_attributes=(anaf) ⇒ Object



222
223
224
# File 'lib/brick/config.rb', line 222

def nested_attributes=(anaf)
  @mutex.synchronize { @nested_attributes = anaf }
end

#not_nullablesObject



453
454
455
# File 'lib/brick/config.rb', line 453

def not_nullables
  @mutex.synchronize { @not_nullables }
end

#not_nullables=(columns) ⇒ Object



457
458
459
# File 'lib/brick/config.rb', line 457

def not_nullables=(columns)
  @mutex.synchronize { @not_nullables = columns }
end

#omit_empty_tables_in_dropdownObject



461
462
463
# File 'lib/brick/config.rb', line 461

def omit_empty_tables_in_dropdown
  @mutex.synchronize { @omit_empty_tables_in_dropdown }
end

#omit_empty_tables_in_dropdown=(field_set) ⇒ Object



465
466
467
# File 'lib/brick/config.rb', line 465

def omit_empty_tables_in_dropdown=(field_set)
  @mutex.synchronize { @omit_empty_tables_in_dropdown = field_set }
end

#orderObject



408
409
410
# File 'lib/brick/config.rb', line 408

def order
  @mutex.synchronize { @order || {} }
end

#order=(orders) ⇒ Object

Get something like: Override how code sorts with:

{ 'on_call_list' => { code: "ORDER BY STRING_TO_ARRAY(code, '.')::int[]" } }

Specify default thing to order_by with:

{ 'on_call_list' => { _brick_default: [:last_name, :first_name] } }
{ 'on_call_list' => { _brick_default: :sequence } }


418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/brick/config.rb', line 418

def order=(orders)
  @mutex.synchronize do
    case (brick_default = orders.fetch(:_brick_default, nil))
    when NilClass
      orders[:_brick_default] = orders.keys.reject { |k| k == :_brick_default }.first
    when String
      orders[:_brick_default] = [brick_default.to_sym]
    when Symbol
      orders[:_brick_default] = [brick_default]
    end
    @order = orders
  end
end

#path_prefixObject

Any path prefixing to apply to all auto-generated Brick routes



42
43
44
# File 'lib/brick/config.rb', line 42

def path_prefix
  @mutex.synchronize { @path_prefix }
end

#path_prefix=(path) ⇒ Object



46
47
48
# File 'lib/brick/config.rb', line 46

def path_prefix=(path)
  @mutex.synchronize { @path_prefix = path }
end

#polymorphicsObject

Polymorphic associations



262
263
264
# File 'lib/brick/config.rb', line 262

def polymorphics
  @mutex.synchronize { @polymorphics ||= {} }
end

#polymorphics=(polys) ⇒ Object



266
267
268
# File 'lib/brick/config.rb', line 266

def polymorphics=(polys)
  @mutex.synchronize { @polymorphics = polys }
end

#schema_behaviorObject



322
323
324
# File 'lib/brick/config.rb', line 322

def schema_behavior
  @mutex.synchronize { @schema_behavior ||= {} }
end

#schema_behavior=(schema) ⇒ Object



326
327
328
# File 'lib/brick/config.rb', line 326

def schema_behavior=(schema)
  @mutex.synchronize { @schema_behavior = schema }
end

#sidescrollObject



290
291
292
# File 'lib/brick/config.rb', line 290

def sidescroll
  @mutex.synchronize { @sidescroll ||= {} }
end

#sidescroll=(scroll) ⇒ Object



294
295
296
# File 'lib/brick/config.rb', line 294

def sidescroll=(scroll)
  @mutex.synchronize { @sidescroll = scroll }
end

#skip_database_viewsObject



360
361
362
# File 'lib/brick/config.rb', line 360

def skip_database_views
  @mutex.synchronize { @skip_database_views }
end

#skip_database_views=(disable) ⇒ Object



364
365
366
# File 'lib/brick/config.rb', line 364

def skip_database_views=(disable)
  @mutex.synchronize { @skip_database_views = disable }
end

#skip_index_hmsObject

Skip showing counts for these specific has_many associations when building auto-generated #index views



195
196
197
# File 'lib/brick/config.rb', line 195

def skip_index_hms
  @mutex.synchronize { @skip_index_hms || {} }
end

#skip_index_hms=(skips) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/brick/config.rb', line 199

def skip_index_hms=(skips)
  @mutex.synchronize do
    @skip_index_hms ||= skips.each_with_object({}) do |v, s|
                          class_name, assoc_name = v.split('.')
                          (s[class_name] ||= {})[assoc_name.to_sym] = nil
                        end
  end
end

#sti_namespace_prefixesObject



314
315
316
# File 'lib/brick/config.rb', line 314

def sti_namespace_prefixes
  @mutex.synchronize { @sti_namespace_prefixes ||= {} }
end

#sti_namespace_prefixes=(prefixes) ⇒ Object



318
319
320
# File 'lib/brick/config.rb', line 318

def sti_namespace_prefixes=(prefixes)
  @mutex.synchronize { @sti_namespace_prefixes = prefixes }
end

#sti_type_columnObject



330
331
332
# File 'lib/brick/config.rb', line 330

def sti_type_column
  @mutex.synchronize { @sti_type_column ||= {} }
end

#sti_type_column=(type_col) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/brick/config.rb', line 334

def sti_type_column=(type_col)
  @mutex.synchronize do
    (@sti_type_column = type_col).each_with_object({}) do |v, s|
      if v.last.nil?
        # Set an STI type column generally
        ActiveRecord::Base.inheritance_column = v.first
      else
        # Custom STI type columns for models built from specific tables
        (v.last.is_a?(Array) ? v.last : [v.last]).each do |table|
          if (relation = ::Brick.relations.fetch(table, nil))
            relation[:sti_col] = v.first
          end
        end
      end
    end
  end
end

#table_name_prefixesObject



392
393
394
# File 'lib/brick/config.rb', line 392

def table_name_prefixes
  @mutex.synchronize { @table_name_prefixes ||= {} }
end

#table_name_prefixes=(value) ⇒ Object



396
397
398
# File 'lib/brick/config.rb', line 396

def table_name_prefixes=(value)
  @mutex.synchronize { @table_name_prefixes = value }
end

#treat_as_associativeObject

Tables to treat as associative, even when they have data columns



236
237
238
# File 'lib/brick/config.rb', line 236

def treat_as_associative
  @mutex.synchronize { @treat_as_associative }
end

#treat_as_associative=(tables) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/brick/config.rb', line 240

def treat_as_associative=(tables)
  @mutex.synchronize do
    @treat_as_associative = if tables.is_a?(Hash)
                              tables.each_with_object({}) do |v, s|
                                # If it's :constellation, or anything else in a hash, we'll take its value
                                # (and hopefully in this case that would be either a string or nil)
                                dsl = ((v.last.is_a?(Symbol) && v.last) || v.last&.values&.last)
                                unless (dsl ||= '').is_a?(String) || dsl.is_a?(Symbol)
                                  puts "Was really expecting #{v.first} / #{v.last.first&.first} / #{dsl} to be a string, " +
                                       "so will disregard #{dsl} and just turn on simple constellation view for #{v.first}."
                                end
                                s[v.first] = v.last.is_a?(Hash) ? dsl : v.last
                              end
                            elsif tables.is_a?(String) # comma-separated list?
                              tables.split(',').each_with_object({}) { |v, s| s[v.trim] = nil }
                            else # Expecting an Array, and have no special presentation
                              tables&.each_with_object({}) { |v, s| s[v] = nil }
                            end
  end
end

#treat_as_moduleObject



400
401
402
# File 'lib/brick/config.rb', line 400

def treat_as_module
  @mutex.synchronize { @treat_as_module || [] }
end

#treat_as_module=(mod_names) ⇒ Object



404
405
406
# File 'lib/brick/config.rb', line 404

def treat_as_module=(mod_names)
  @mutex.synchronize { @treat_as_module = mod_names }
end