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

#add_orphansObject

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



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

def add_orphans
  true
end

#add_statusObject

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



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

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



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

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

#always_load_fields=(field_set) ⇒ Object



435
436
437
# File 'lib/brick/config.rb', line 435

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



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

def controllers_inherit_from
  @mutex.synchronize { @controllers_inherit_from }
end

#controllers_inherit_from=(value) ⇒ Object



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

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



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

def default_route_fallback
  @mutex.synchronize { @default_route_fallback }
end

#default_route_fallback=(resource_name) ⇒ Object



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

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

#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



343
344
345
# File 'lib/brick/config.rb', line 343

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

#exclude_tables=(value) ⇒ Object



347
348
349
# File 'lib/brick/config.rb', line 347

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



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

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

#ignore_migration_fks=(relations) ⇒ Object



443
444
445
# File 'lib/brick/config.rb', line 443

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

#json_columnsObject



253
254
255
# File 'lib/brick/config.rb', line 253

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

#json_columns=(cols) ⇒ Object



257
258
259
# File 'lib/brick/config.rb', line 257

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

#licenseObject



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

def license
  @mutex.synchronize { @license }
end

#license=(key) ⇒ Object



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

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



263
264
265
266
267
# File 'lib/brick/config.rb', line 263

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



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

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

#metadata_columnsObject



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

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

#metadata_columns=(columns) ⇒ Object



411
412
413
# File 'lib/brick/config.rb', line 411

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



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

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

#model_descrips=(descrips) ⇒ Object



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

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

#models_inherit_fromObject



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

def models_inherit_from
  @mutex.synchronize { @models_inherit_from }
end

#models_inherit_from=(value) ⇒ Object



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

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



415
416
417
# File 'lib/brick/config.rb', line 415

def not_nullables
  @mutex.synchronize { @not_nullables }
end

#not_nullables=(columns) ⇒ Object



419
420
421
# File 'lib/brick/config.rb', line 419

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

#omit_empty_tables_in_dropdownObject



423
424
425
# File 'lib/brick/config.rb', line 423

def omit_empty_tables_in_dropdown
  @mutex.synchronize { @omit_empty_tables_in_dropdown }
end

#omit_empty_tables_in_dropdown=(field_set) ⇒ Object



427
428
429
# File 'lib/brick/config.rb', line 427

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

#orderObject



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

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 } }


393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/brick/config.rb', line 393

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



245
246
247
# File 'lib/brick/config.rb', line 245

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

#polymorphics=(polys) ⇒ Object



249
250
251
# File 'lib/brick/config.rb', line 249

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

#schema_behaviorObject



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

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

#schema_behavior=(schema) ⇒ Object



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

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

#sidescrollObject



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

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

#sidescroll=(scroll) ⇒ Object



277
278
279
# File 'lib/brick/config.rb', line 277

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

#skip_database_viewsObject



335
336
337
# File 'lib/brick/config.rb', line 335

def skip_database_views
  @mutex.synchronize { @skip_database_views }
end

#skip_database_views=(disable) ⇒ Object



339
340
341
# File 'lib/brick/config.rb', line 339

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



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

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

#sti_namespace_prefixes=(prefixes) ⇒ Object



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

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

#sti_type_columnObject



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

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

#sti_type_column=(type_col) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/brick/config.rb', line 309

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



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

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

#table_name_prefixes=(value) ⇒ Object



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

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
# File 'lib/brick/config.rb', line 240

def treat_as_associative=(tables)
  @mutex.synchronize { @treat_as_associative = tables }
end

#treat_as_moduleObject



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

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

#treat_as_module=(mod_names) ⇒ Object



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

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