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
- #api_root ⇒ Object
- #api_root=(path) ⇒ Object
- #api_version ⇒ Object
- #api_version=(ver) ⇒ 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
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #metadata_columns ⇒ Object
- #metadata_columns=(columns) ⇒ Object
- #model_descrips ⇒ Object
- #model_descrips=(descrips) ⇒ Object
- #models_inherit_from ⇒ Object
- #models_inherit_from=(value) ⇒ 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
- #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”)
282 283 284 |
# File 'lib/brick/config.rb', line 282 def add_orphans true end |
#add_status ⇒ Object
Add status page showing all resources and what files have been built out for them
277 278 279 |
# File 'lib/brick/config.rb', line 277 def add_status true end |
#additional_references ⇒ Object
Additional table associations to use (Think of these as virtual foreign keys perhaps)
94 95 96 |
# File 'lib/brick/config.rb', line 94 def additional_references @mutex.synchronize { @additional_references } end |
#additional_references=(references) ⇒ Object
98 99 100 |
# File 'lib/brick/config.rb', line 98 def additional_references=(references) @mutex.synchronize { @additional_references = references } end |
#api_root ⇒ Object
76 77 78 79 |
# File 'lib/brick/config.rb', line 76 def api_root ver = api_version @mutex.synchronize { @api_root || "/api/#{ver}/" } end |
#api_root=(path) ⇒ Object
81 82 83 |
# File 'lib/brick/config.rb', line 81 def api_root=(path) @mutex.synchronize { @api_root = path } end |
#api_version ⇒ Object
85 86 87 |
# File 'lib/brick/config.rb', line 85 def api_version @mutex.synchronize { @api_version || 'v1' } end |
#api_version=(ver) ⇒ Object
89 90 91 |
# File 'lib/brick/config.rb', line 89 def api_version=(ver) @mutex.synchronize { @api_version = ver } end |
#custom_columns ⇒ Object
Custom columns to add to a table, minimally defined with a name and DSL string
103 104 105 |
# File 'lib/brick/config.rb', line 103 def custom_columns @mutex.synchronize { @custom_columns } end |
#custom_columns=(cust_cols) ⇒ Object
107 108 109 |
# File 'lib/brick/config.rb', line 107 def custom_columns=(cust_cols) @mutex.synchronize { @custom_columns = cust_cols } end |
#default_route_fallback ⇒ Object
196 197 198 |
# File 'lib/brick/config.rb', line 196 def default_route_fallback @mutex.synchronize { @default_route_fallback } end |
#default_route_fallback=(resource_name) ⇒ Object
200 201 202 |
# File 'lib/brick/config.rb', line 200 def default_route_fallback=(resource_name) @mutex.synchronize { @default_route_fallback = resource_name } end |
#enable_api ⇒ Object
68 69 70 |
# File 'lib/brick/config.rb', line 68 def enable_api @mutex.synchronize { @enable_api } end |
#enable_api=(enable) ⇒ Object
72 73 74 |
# File 'lib/brick/config.rb', line 72 def enable_api=(enable) @mutex.synchronize { @enable_api = enable } end |
#enable_controllers ⇒ Object
Indicates whether Brick controllers are on or off. Default: true.
42 43 44 |
# File 'lib/brick/config.rb', line 42 def enable_controllers @mutex.synchronize { !!@enable_controllers } end |
#enable_controllers=(enable) ⇒ Object
46 47 48 |
# File 'lib/brick/config.rb', line 46 def enable_controllers=(enable) @mutex.synchronize { @enable_controllers = enable } end |
#enable_models ⇒ Object
Indicates whether Brick models are on or off. Default: true.
33 34 35 |
# File 'lib/brick/config.rb', line 33 def enable_models @mutex.synchronize { !!@enable_models } end |
#enable_models=(enable) ⇒ Object
37 38 39 |
# File 'lib/brick/config.rb', line 37 def enable_models=(enable) @mutex.synchronize { @enable_models = enable } end |
#enable_routes ⇒ Object
Indicates whether Brick routes are on or off. Default: true.
60 61 62 |
# File 'lib/brick/config.rb', line 60 def enable_routes @mutex.synchronize { !!@enable_routes } end |
#enable_routes=(enable) ⇒ Object
64 65 66 |
# File 'lib/brick/config.rb', line 64 def enable_routes=(enable) @mutex.synchronize { @enable_routes = enable } end |
#enable_views ⇒ Object
Indicates whether Brick views are on or off. Default: true.
51 52 53 |
# File 'lib/brick/config.rb', line 51 def enable_views @mutex.synchronize { !!@enable_views } end |
#enable_views=(enable) ⇒ Object
55 56 57 |
# File 'lib/brick/config.rb', line 55 def enable_views=(enable) @mutex.synchronize { @enable_views = enable } end |
#exclude_hms ⇒ Object
Skip creating a has_many association for these
112 113 114 |
# File 'lib/brick/config.rb', line 112 def exclude_hms @mutex.synchronize { @exclude_hms } end |
#exclude_hms=(skips) ⇒ Object
116 117 118 |
# File 'lib/brick/config.rb', line 116 def exclude_hms=(skips) @mutex.synchronize { @exclude_hms = skips } end |
#exclude_tables ⇒ Object
212 213 214 |
# File 'lib/brick/config.rb', line 212 def exclude_tables @mutex.synchronize { @exclude_tables || [] } end |
#exclude_tables=(value) ⇒ Object
216 217 218 |
# File 'lib/brick/config.rb', line 216 def exclude_tables=(value) @mutex.synchronize { @exclude_tables = value } end |
#has_ones ⇒ Object
Associations to treat as a has_one
135 136 137 |
# File 'lib/brick/config.rb', line 135 def has_ones @mutex.synchronize { @has_ones } end |
#has_ones=(hos) ⇒ Object
139 140 141 |
# File 'lib/brick/config.rb', line 139 def has_ones=(hos) @mutex.synchronize { @has_ones = hos } end |
#metadata_columns ⇒ Object
260 261 262 |
# File 'lib/brick/config.rb', line 260 def @mutex.synchronize { } end |
#metadata_columns=(columns) ⇒ Object
264 265 266 |
# File 'lib/brick/config.rb', line 264 def (columns) @mutex.synchronize { = columns } end |
#model_descrips ⇒ Object
152 153 154 |
# File 'lib/brick/config.rb', line 152 def model_descrips @mutex.synchronize { @model_descrips ||= {} } end |
#model_descrips=(descrips) ⇒ Object
156 157 158 |
# File 'lib/brick/config.rb', line 156 def model_descrips=(descrips) @mutex.synchronize { @model_descrips = descrips } end |
#models_inherit_from ⇒ Object
220 221 222 |
# File 'lib/brick/config.rb', line 220 def models_inherit_from @mutex.synchronize { @models_inherit_from } end |
#models_inherit_from=(value) ⇒ Object
224 225 226 |
# File 'lib/brick/config.rb', line 224 def models_inherit_from=(value) @mutex.synchronize { @models_inherit_from = value } end |
#not_nullables ⇒ Object
268 269 270 |
# File 'lib/brick/config.rb', line 268 def not_nullables @mutex.synchronize { @not_nullables } end |
#not_nullables=(columns) ⇒ Object
272 273 274 |
# File 'lib/brick/config.rb', line 272 def not_nullables=(columns) @mutex.synchronize { @not_nullables = columns } end |
#order ⇒ Object
236 237 238 |
# File 'lib/brick/config.rb', line 236 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 } }
246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/brick/config.rb', line 246 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
24 25 26 |
# File 'lib/brick/config.rb', line 24 def path_prefix @mutex.synchronize { @path_prefix } end |
#path_prefix=(path) ⇒ Object
28 29 30 |
# File 'lib/brick/config.rb', line 28 def path_prefix=(path) @mutex.synchronize { @path_prefix = path } end |
#polymorphics ⇒ Object
Polymorphic associations
144 145 146 |
# File 'lib/brick/config.rb', line 144 def polymorphics @mutex.synchronize { @polymorphics } end |
#polymorphics=(polys) ⇒ Object
148 149 150 |
# File 'lib/brick/config.rb', line 148 def polymorphics=(polys) @mutex.synchronize { @polymorphics = polys } end |
#schema_behavior ⇒ Object
168 169 170 |
# File 'lib/brick/config.rb', line 168 def schema_behavior @mutex.synchronize { @schema_behavior ||= {} } end |
#schema_behavior=(schema) ⇒ Object
172 173 174 |
# File 'lib/brick/config.rb', line 172 def schema_behavior=(schema) @mutex.synchronize { @schema_behavior = schema } end |
#skip_database_views ⇒ Object
204 205 206 |
# File 'lib/brick/config.rb', line 204 def skip_database_views @mutex.synchronize { @skip_database_views } end |
#skip_database_views=(disable) ⇒ Object
208 209 210 |
# File 'lib/brick/config.rb', line 208 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
121 122 123 |
# File 'lib/brick/config.rb', line 121 def skip_index_hms @mutex.synchronize { @skip_index_hms || {} } end |
#skip_index_hms=(skips) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/brick/config.rb', line 125 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
160 161 162 |
# File 'lib/brick/config.rb', line 160 def sti_namespace_prefixes @mutex.synchronize { @sti_namespace_prefixes ||= {} } end |
#sti_namespace_prefixes=(prefixes) ⇒ Object
164 165 166 |
# File 'lib/brick/config.rb', line 164 def sti_namespace_prefixes=(prefixes) @mutex.synchronize { @sti_namespace_prefixes = prefixes } end |
#sti_type_column ⇒ Object
176 177 178 |
# File 'lib/brick/config.rb', line 176 def sti_type_column @mutex.synchronize { @sti_type_column ||= {} } end |
#sti_type_column=(type_col) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/brick/config.rb', line 180 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| ::Brick.relations[table][:sti_col] = v.first end end end end end |
#table_name_prefixes ⇒ Object
228 229 230 |
# File 'lib/brick/config.rb', line 228 def table_name_prefixes @mutex.synchronize { @table_name_prefixes } end |
#table_name_prefixes=(value) ⇒ Object
232 233 234 |
# File 'lib/brick/config.rb', line 232 def table_name_prefixes=(value) @mutex.synchronize { @table_name_prefixes = value } end |