Class: Brick::Config
Overview
Global configuration affecting all threads. Some thread-specific configuration can be found in ‘brick.rb`, others in `controller.rb`.
Instance Attribute Summary collapse
-
#association_reify_error_behaviour ⇒ Object
Returns the value of attribute association_reify_error_behaviour.
-
#object_changes_adapter ⇒ Object
Returns the value of attribute object_changes_adapter.
-
#root_model ⇒ Object
Returns the value of attribute root_model.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
-
#version_limit ⇒ Object
Returns the value of attribute version_limit.
Instance Method Summary collapse
-
#add_orphans ⇒ Object
Add a special page to show references to non-existent records (“orphans”).
-
#add_status ⇒ Object
Add status page showing all resources and what files have been built out for them.
-
#additional_references ⇒ Object
Additional table associations to use (Think of these as virtual foreign keys perhaps).
- #additional_references=(references) ⇒ Object
- #always_load_fields ⇒ Object
- #always_load_fields=(field_set) ⇒ Object
- #api_add_view_prefix ⇒ Object
- #api_add_view_prefix=(view_prefix) ⇒ Object
-
#api_column_renaming ⇒ Object
Allows you to rename and exclude columns either specific to a given API version, or generally for a database object name.
- #api_column_renaming=(renames) ⇒ Object
- #api_filter ⇒ Object
- #api_filter=(proc) ⇒ Object
- #api_remove_view_prefix ⇒ Object
- #api_remove_view_prefix=(view_prefix) ⇒ Object
- #api_roots ⇒ Object
- #api_roots=(path) ⇒ Object
-
#api_view_prefix ⇒ Object
All the view prefix things.
- #api_view_prefix=(view_prefix) ⇒ Object
- #controllers_inherit_from ⇒ Object
- #controllers_inherit_from=(value) ⇒ Object
-
#custom_columns ⇒ Object
Custom columns to add to a table, minimally defined with a name and DSL string.
- #custom_columns=(cust_cols) ⇒ Object
- #default_route_fallback ⇒ Object
- #default_route_fallback=(resource_name) ⇒ Object
- #enable_api ⇒ Object
- #enable_api=(enable) ⇒ Object
-
#enable_controllers ⇒ Object
Indicates whether Brick controllers are on or off.
- #enable_controllers=(enable) ⇒ Object
-
#enable_models ⇒ Object
Indicates whether Brick models are on or off.
- #enable_models=(enable) ⇒ Object
-
#enable_routes ⇒ Object
Indicates whether Brick routes are on or off.
- #enable_routes=(enable) ⇒ Object
-
#enable_views ⇒ Object
Indicates whether Brick views are on or off.
- #enable_views=(enable) ⇒ Object
-
#exclude_hms ⇒ Object
Skip creating a has_many association for these.
- #exclude_hms=(skips) ⇒ Object
- #exclude_tables ⇒ Object
- #exclude_tables=(value) ⇒ Object
-
#has_ones ⇒ Object
Associations to treat as a has_one.
- #has_ones=(hos) ⇒ Object
- #ignore_migration_fks ⇒ Object
- #ignore_migration_fks=(relations) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #json_columns ⇒ Object
- #json_columns=(cols) ⇒ Object
- #license ⇒ Object
- #license=(key) ⇒ Object
- #metadata_columns ⇒ Object
- #metadata_columns=(columns) ⇒ Object
- #mode ⇒ Object
- #mode=(setting) ⇒ Object
- #model_descrips ⇒ Object
- #model_descrips=(descrips) ⇒ Object
- #models_inherit_from ⇒ Object
- #models_inherit_from=(value) ⇒ Object
-
#nested_attributes ⇒ Object
Associations upon which to add #accepts_nested_attributes_for logic.
- #nested_attributes=(anaf) ⇒ Object
- #not_nullables ⇒ Object
- #not_nullables=(columns) ⇒ Object
- #order ⇒ Object
-
#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 } }.
-
#path_prefix ⇒ Object
Any path prefixing to apply to all auto-generated Brick routes.
- #path_prefix=(path) ⇒ Object
-
#polymorphics ⇒ Object
Polymorphic associations.
- #polymorphics=(polys) ⇒ Object
- #schema_behavior ⇒ Object
- #schema_behavior=(schema) ⇒ Object
- #sidescroll ⇒ Object
- #sidescroll=(scroll) ⇒ Object
- #skip_database_views ⇒ Object
- #skip_database_views=(disable) ⇒ Object
-
#skip_index_hms ⇒ Object
Skip showing counts for these specific has_many associations when building auto-generated #index views.
- #skip_index_hms=(skips) ⇒ Object
- #sti_namespace_prefixes ⇒ Object
- #sti_namespace_prefixes=(prefixes) ⇒ Object
- #sti_type_column ⇒ Object
- #sti_type_column=(type_col) ⇒ Object
- #table_name_prefixes ⇒ Object
- #table_name_prefixes=(value) ⇒ Object
Constructor Details
#initialize ⇒ Config
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_behaviour ⇒ Object
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_adapter ⇒ Object
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_model ⇒ Object
Returns the value of attribute root_model.
11 12 13 |
# File 'lib/brick/config.rb', line 11 def root_model @root_model end |
#serializer ⇒ Object
Returns the value of attribute serializer.
11 12 13 |
# File 'lib/brick/config.rb', line 11 def serializer @serializer end |
#version_limit ⇒ Object
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_orphans ⇒ Object
Add a special page to show references to non-existent records (“orphans”)
397 398 399 |
# File 'lib/brick/config.rb', line 397 def add_orphans true end |
#add_status ⇒ Object
Add status page showing all resources and what files have been built out for them
392 393 394 |
# File 'lib/brick/config.rb', line 392 def add_status true end |
#additional_references ⇒ Object
Additional table associations to use (Think of these as virtual foreign keys perhaps)
158 159 160 |
# File 'lib/brick/config.rb', line 158 def additional_references @mutex.synchronize { @additional_references } end |
#additional_references=(references) ⇒ Object
162 163 164 |
# File 'lib/brick/config.rb', line 162 def additional_references=(references) @mutex.synchronize { @additional_references = references } end |
#always_load_fields ⇒ Object
375 376 377 |
# File 'lib/brick/config.rb', line 375 def always_load_fields @mutex.synchronize { @always_load_fields || {} } end |
#always_load_fields=(field_set) ⇒ Object
379 380 381 |
# File 'lib/brick/config.rb', line 379 def always_load_fields=(field_set) @mutex.synchronize { @always_load_fields = field_set } end |
#api_add_view_prefix ⇒ Object
149 150 151 |
# File 'lib/brick/config.rb', line 149 def api_add_view_prefix @mutex.synchronize { @api_add_view_prefix || @api_view_prefix } end |
#api_add_view_prefix=(view_prefix) ⇒ Object
153 154 155 |
# File 'lib/brick/config.rb', line 153 def api_add_view_prefix=(view_prefix) @mutex.synchronize { @api_add_view_prefix = view_prefix } end |
#api_column_renaming ⇒ Object
Allows you to rename and exclude columns either specific to a given API version, or generally for a database object name
124 125 126 |
# File 'lib/brick/config.rb', line 124 def api_column_renaming @mutex.synchronize { @api_column_renaming } end |
#api_column_renaming=(renames) ⇒ Object
128 129 130 |
# File 'lib/brick/config.rb', line 128 def api_column_renaming=(renames) @mutex.synchronize { @api_column_renaming = renames } end |
#api_filter ⇒ Object
105 106 107 |
# File 'lib/brick/config.rb', line 105 def api_filter @mutex.synchronize { @api_filter } end |
#api_filter=(proc) ⇒ Object
109 110 111 |
# File 'lib/brick/config.rb', line 109 def api_filter=(proc) @mutex.synchronize { @api_filter = proc } end |
#api_remove_view_prefix ⇒ Object
141 142 143 |
# File 'lib/brick/config.rb', line 141 def api_remove_view_prefix @mutex.synchronize { @api_remove_view_prefix || @api_view_prefix } end |
#api_remove_view_prefix=(view_prefix) ⇒ Object
145 146 147 |
# File 'lib/brick/config.rb', line 145 def api_remove_view_prefix=(view_prefix) @mutex.synchronize { @api_remove_view_prefix = view_prefix } end |
#api_roots ⇒ Object
97 98 99 |
# File 'lib/brick/config.rb', line 97 def api_roots @mutex.synchronize { @api_roots || ["/api/v1/"] } end |
#api_roots=(path) ⇒ Object
101 102 103 |
# File 'lib/brick/config.rb', line 101 def api_roots=(path) @mutex.synchronize { @api_roots = path } end |
#api_view_prefix ⇒ Object
All the view prefix things
133 134 135 |
# File 'lib/brick/config.rb', line 133 def api_view_prefix @mutex.synchronize { @api_view_prefix } end |
#api_view_prefix=(view_prefix) ⇒ Object
137 138 139 |
# File 'lib/brick/config.rb', line 137 def api_view_prefix=(view_prefix) @mutex.synchronize { @api_view_prefix = view_prefix } end |
#controllers_inherit_from ⇒ Object
319 320 321 |
# File 'lib/brick/config.rb', line 319 def controllers_inherit_from @mutex.synchronize { @controllers_inherit_from } end |
#controllers_inherit_from=(value) ⇒ Object
323 324 325 |
# File 'lib/brick/config.rb', line 323 def controllers_inherit_from=(value) @mutex.synchronize { @controllers_inherit_from = value } end |
#custom_columns ⇒ Object
Custom columns to add to a table, minimally defined with a name and DSL string
167 168 169 |
# File 'lib/brick/config.rb', line 167 def custom_columns @mutex.synchronize { @custom_columns } end |
#custom_columns=(cust_cols) ⇒ Object
171 172 173 |
# File 'lib/brick/config.rb', line 171 def custom_columns=(cust_cols) @mutex.synchronize { @custom_columns = cust_cols } end |
#default_route_fallback ⇒ Object
287 288 289 |
# File 'lib/brick/config.rb', line 287 def default_route_fallback @mutex.synchronize { @default_route_fallback } end |
#default_route_fallback=(resource_name) ⇒ Object
291 292 293 |
# File 'lib/brick/config.rb', line 291 def default_route_fallback=(resource_name) @mutex.synchronize { @default_route_fallback = resource_name } end |
#enable_api ⇒ Object
89 90 91 |
# File 'lib/brick/config.rb', line 89 def enable_api @mutex.synchronize { @enable_api } end |
#enable_api=(enable) ⇒ Object
93 94 95 |
# File 'lib/brick/config.rb', line 93 def enable_api=(enable) @mutex.synchronize { @enable_api = enable } end |
#enable_controllers ⇒ Object
Indicates whether Brick controllers are on or off. Default: true.
60 61 62 63 |
# File 'lib/brick/config.rb', line 60 def enable_controllers brick_mode = mode @mutex.synchronize { brick_mode == :on && (@enable_controllers.nil? || @enable_controllers) } end |
#enable_controllers=(enable) ⇒ Object
65 66 67 |
# File 'lib/brick/config.rb', line 65 def enable_controllers=(enable) @mutex.synchronize { @enable_controllers = enable } end |
#enable_models ⇒ Object
Indicates whether Brick models are on or off. Default: true.
50 51 52 53 |
# File 'lib/brick/config.rb', line 50 def enable_models brick_mode = mode @mutex.synchronize { brick_mode == :on && (@enable_models.nil? || @enable_models) } end |
#enable_models=(enable) ⇒ Object
55 56 57 |
# File 'lib/brick/config.rb', line 55 def enable_models=(enable) @mutex.synchronize { @enable_models = enable } end |
#enable_routes ⇒ Object
Indicates whether Brick routes are on or off. Default: true.
80 81 82 83 |
# File 'lib/brick/config.rb', line 80 def enable_routes brick_mode = mode @mutex.synchronize { brick_mode == :on && (@enable_routes.nil? || @enable_routes) } end |
#enable_routes=(enable) ⇒ Object
85 86 87 |
# File 'lib/brick/config.rb', line 85 def enable_routes=(enable) @mutex.synchronize { @enable_routes = enable } end |
#enable_views ⇒ Object
Indicates whether Brick views are on or off. Default: true.
70 71 72 73 |
# File 'lib/brick/config.rb', line 70 def enable_views brick_mode = mode @mutex.synchronize { brick_mode == :on && (@enable_views.nil? || @enable_views) } end |
#enable_views=(enable) ⇒ Object
75 76 77 |
# File 'lib/brick/config.rb', line 75 def enable_views=(enable) @mutex.synchronize { @enable_views = enable } end |
#exclude_hms ⇒ Object
Skip creating a has_many association for these
176 177 178 |
# File 'lib/brick/config.rb', line 176 def exclude_hms @mutex.synchronize { @exclude_hms } end |
#exclude_hms=(skips) ⇒ Object
180 181 182 |
# File 'lib/brick/config.rb', line 180 def exclude_hms=(skips) @mutex.synchronize { @exclude_hms = skips } end |
#exclude_tables ⇒ Object
303 304 305 |
# File 'lib/brick/config.rb', line 303 def exclude_tables @mutex.synchronize { @exclude_tables || [] } end |
#exclude_tables=(value) ⇒ Object
307 308 309 |
# File 'lib/brick/config.rb', line 307 def exclude_tables=(value) @mutex.synchronize { @exclude_tables = value } end |
#has_ones ⇒ Object
Associations to treat as a has_one
199 200 201 |
# File 'lib/brick/config.rb', line 199 def has_ones @mutex.synchronize { @has_ones } end |
#has_ones=(hos) ⇒ Object
203 204 205 |
# File 'lib/brick/config.rb', line 203 def has_ones=(hos) @mutex.synchronize { @has_ones = hos } end |
#ignore_migration_fks ⇒ Object
383 384 385 |
# File 'lib/brick/config.rb', line 383 def ignore_migration_fks @mutex.synchronize { @ignore_migration_fks || [] } end |
#ignore_migration_fks=(relations) ⇒ Object
387 388 389 |
# File 'lib/brick/config.rb', line 387 def ignore_migration_fks=(relations) @mutex.synchronize { @ignore_migration_fks = relations } end |
#json_columns ⇒ Object
225 226 227 |
# File 'lib/brick/config.rb', line 225 def json_columns @mutex.synchronize { @json_columns ||= {} } end |
#json_columns=(cols) ⇒ Object
229 230 231 |
# File 'lib/brick/config.rb', line 229 def json_columns=(cols) @mutex.synchronize { @json_columns = cols } end |
#license ⇒ Object
401 402 403 |
# File 'lib/brick/config.rb', line 401 def license @mutex.synchronize { @license } end |
#license=(key) ⇒ Object
405 406 407 |
# File 'lib/brick/config.rb', line 405 def license=(key) @mutex.synchronize { @license = key } end |
#metadata_columns ⇒ Object
359 360 361 |
# File 'lib/brick/config.rb', line 359 def @mutex.synchronize { @metadata_columns } end |
#metadata_columns=(columns) ⇒ Object
363 364 365 |
# File 'lib/brick/config.rb', line 363 def (columns) @mutex.synchronize { @metadata_columns = columns } end |
#mode ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/brick/config.rb', line 23 def mode @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
36 37 38 |
# File 'lib/brick/config.rb', line 36 def mode=(setting) @mutex.synchronize { @brick_mode = setting unless @brick_mode == :on } end |
#model_descrips ⇒ Object
241 242 243 |
# File 'lib/brick/config.rb', line 241 def model_descrips @mutex.synchronize { @model_descrips ||= {} } end |
#model_descrips=(descrips) ⇒ Object
245 246 247 |
# File 'lib/brick/config.rb', line 245 def model_descrips=(descrips) @mutex.synchronize { @model_descrips = descrips } end |
#models_inherit_from ⇒ Object
311 312 313 |
# File 'lib/brick/config.rb', line 311 def models_inherit_from @mutex.synchronize { @models_inherit_from } end |
#models_inherit_from=(value) ⇒ Object
315 316 317 |
# File 'lib/brick/config.rb', line 315 def models_inherit_from=(value) @mutex.synchronize { @models_inherit_from = value } end |
#nested_attributes ⇒ Object
Associations upon which to add #accepts_nested_attributes_for logic
208 209 210 |
# File 'lib/brick/config.rb', line 208 def nested_attributes @mutex.synchronize { @nested_attributes } end |
#nested_attributes=(anaf) ⇒ Object
212 213 214 |
# File 'lib/brick/config.rb', line 212 def nested_attributes=(anaf) @mutex.synchronize { @nested_attributes = anaf } end |
#not_nullables ⇒ Object
367 368 369 |
# File 'lib/brick/config.rb', line 367 def not_nullables @mutex.synchronize { @not_nullables } end |
#not_nullables=(columns) ⇒ Object
371 372 373 |
# File 'lib/brick/config.rb', line 371 def not_nullables=(columns) @mutex.synchronize { @not_nullables = columns } end |
#order ⇒ Object
335 336 337 |
# File 'lib/brick/config.rb', line 335 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 } }
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/brick/config.rb', line 345 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_prefix ⇒ Object
Any path prefixing to apply to all auto-generated Brick routes
41 42 43 |
# File 'lib/brick/config.rb', line 41 def path_prefix @mutex.synchronize { @path_prefix } end |
#path_prefix=(path) ⇒ Object
45 46 47 |
# File 'lib/brick/config.rb', line 45 def path_prefix=(path) @mutex.synchronize { @path_prefix = path } end |
#polymorphics ⇒ Object
Polymorphic associations
217 218 219 |
# File 'lib/brick/config.rb', line 217 def polymorphics @mutex.synchronize { @polymorphics } end |
#polymorphics=(polys) ⇒ Object
221 222 223 |
# File 'lib/brick/config.rb', line 221 def polymorphics=(polys) @mutex.synchronize { @polymorphics = polys } end |
#schema_behavior ⇒ Object
257 258 259 |
# File 'lib/brick/config.rb', line 257 def schema_behavior @mutex.synchronize { @schema_behavior ||= {} } end |
#schema_behavior=(schema) ⇒ Object
261 262 263 |
# File 'lib/brick/config.rb', line 261 def schema_behavior=(schema) @mutex.synchronize { @schema_behavior = schema } end |
#sidescroll ⇒ Object
233 234 235 |
# File 'lib/brick/config.rb', line 233 def sidescroll @mutex.synchronize { @sidescroll ||= {} } end |
#sidescroll=(scroll) ⇒ Object
237 238 239 |
# File 'lib/brick/config.rb', line 237 def sidescroll=(scroll) @mutex.synchronize { @sidescroll = scroll } end |
#skip_database_views ⇒ Object
295 296 297 |
# File 'lib/brick/config.rb', line 295 def skip_database_views @mutex.synchronize { @skip_database_views } end |
#skip_database_views=(disable) ⇒ Object
299 300 301 |
# File 'lib/brick/config.rb', line 299 def skip_database_views=(disable) @mutex.synchronize { @skip_database_views = disable } end |
#skip_index_hms ⇒ Object
Skip showing counts for these specific has_many associations when building auto-generated #index views
185 186 187 |
# File 'lib/brick/config.rb', line 185 def skip_index_hms @mutex.synchronize { @skip_index_hms || {} } end |
#skip_index_hms=(skips) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/brick/config.rb', line 189 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_prefixes ⇒ Object
249 250 251 |
# File 'lib/brick/config.rb', line 249 def sti_namespace_prefixes @mutex.synchronize { @sti_namespace_prefixes ||= {} } end |
#sti_namespace_prefixes=(prefixes) ⇒ Object
253 254 255 |
# File 'lib/brick/config.rb', line 253 def sti_namespace_prefixes=(prefixes) @mutex.synchronize { @sti_namespace_prefixes = prefixes } end |
#sti_type_column ⇒ Object
265 266 267 |
# File 'lib/brick/config.rb', line 265 def sti_type_column @mutex.synchronize { @sti_type_column ||= {} } end |
#sti_type_column=(type_col) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/brick/config.rb', line 269 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_prefixes ⇒ Object
327 328 329 |
# File 'lib/brick/config.rb', line 327 def table_name_prefixes @mutex.synchronize { @table_name_prefixes } end |
#table_name_prefixes=(value) ⇒ Object
331 332 333 |
# File 'lib/brick/config.rb', line 331 def table_name_prefixes=(value) @mutex.synchronize { @table_name_prefixes = value } end |