Class: RESTFramework::Config
- Inherits:
-
Object
- Object
- RESTFramework::Config
- Defined in:
- lib/rest_framework.rb
Overview
Global configuration should be kept minimal, as controller-level configurations allows multiple APIs to be defined to behave differently.
Constant Summary collapse
- DEFAULT_LABEL_FIELDS =
%w[name label login title email username url].freeze
- DEFAULT_SEARCH_COLUMNS =
DEFAULT_LABEL_FIELDS + %w[description note].freeze
- DEFAULT_READ_ONLY_FIELDS =
%w[ created_at created_by created_by_id updated_at updated_by updated_by_id _method utf8 authenticity_token ].freeze
- DEFAULT_WRITE_ONLY_FIELDS =
%w[ password password_confirmation ].freeze
- DEFAULT_INFLECT_ACRONYMS =
[ "ID", "IDs", "REST", "API", "APIs" ].freeze
Instance Attribute Summary collapse
-
#auto_finalize ⇒ Object
Run ‘rrf_finalize` on controllers automatically using a `TracePoint` hook.
-
#disable_rescue_from ⇒ Object
Disable ‘rescue_from` on the controller mixins.
-
#freeze_config ⇒ Object
Freeze configuration attributes during finalization to prevent accidental mutation.
-
#inflect_acronyms ⇒ Object
List of acronyms to be inflected in controller titles and field labels.
-
#label_fields ⇒ Object
The default label fields to use when generating labels for ‘has_many` associations.
-
#large_reverse_association_tables ⇒ Object
Specify reverse association tables that are typically very large, and therefore should not be added to fields by default.
-
#read_only_fields ⇒ Object
Helper to set global read/write only fields.
-
#register_api_renderer ⇒ Object
Permits use of ‘render(api: obj)` syntax over `render_api(obj)`; `true` by default.
-
#search_columns ⇒ Object
The default search columns to use when generating search filters.
-
#show_backtrace ⇒ Object
Whether the backtrace should be shown in rescued errors.
-
#use_vendored_assets ⇒ Object
Option to use vendored assets (requires sprockets or propshaft) rather than linking to external assets (the default).
-
#write_only_fields ⇒ Object
Returns the value of attribute write_only_fields.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rest_framework.rb', line 192 def initialize self.register_api_renderer = true self.auto_finalize = true self.show_backtrace = Rails.env.development? self.label_fields = DEFAULT_LABEL_FIELDS self.search_columns = DEFAULT_SEARCH_COLUMNS self.read_only_fields = DEFAULT_READ_ONLY_FIELDS self.write_only_fields = DEFAULT_WRITE_ONLY_FIELDS self.inflect_acronyms = DEFAULT_INFLECT_ACRONYMS end |
Instance Attribute Details
#auto_finalize ⇒ Object
Run ‘rrf_finalize` on controllers automatically using a `TracePoint` hook. This is `true` by default, and can be disabled for performance, and must be global because we have to determine this before any controller-specific configuration is set. If this is set to `false`, then you must manually call `rrf_finalize` after any configuration on each controller that needs to participate in:
- Model delegation, for the helper methods to be defined dynamically.
- Websockets, for `::Channel` class to be defined dynamically.
- Controller configuration freezing.
160 161 162 |
# File 'lib/rest_framework.rb', line 160 def auto_finalize @auto_finalize end |
#disable_rescue_from ⇒ Object
Disable ‘rescue_from` on the controller mixins.
173 174 175 |
# File 'lib/rest_framework.rb', line 173 def disable_rescue_from @disable_rescue_from end |
#freeze_config ⇒ Object
Freeze configuration attributes during finalization to prevent accidental mutation.
163 164 165 |
# File 'lib/rest_framework.rb', line 163 def freeze_config @freeze_config end |
#inflect_acronyms ⇒ Object
List of acronyms to be inflected in controller titles and field labels.
186 187 188 |
# File 'lib/rest_framework.rb', line 186 def inflect_acronyms @inflect_acronyms end |
#label_fields ⇒ Object
The default label fields to use when generating labels for ‘has_many` associations.
176 177 178 |
# File 'lib/rest_framework.rb', line 176 def label_fields @label_fields end |
#large_reverse_association_tables ⇒ Object
Specify reverse association tables that are typically very large, and therefore should not be added to fields by default.
167 168 169 |
# File 'lib/rest_framework.rb', line 167 def large_reverse_association_tables @large_reverse_association_tables end |
#read_only_fields ⇒ Object
Helper to set global read/write only fields.
182 183 184 |
# File 'lib/rest_framework.rb', line 182 def read_only_fields @read_only_fields end |
#register_api_renderer ⇒ Object
Permits use of ‘render(api: obj)` syntax over `render_api(obj)`; `true` by default.
150 151 152 |
# File 'lib/rest_framework.rb', line 150 def register_api_renderer @register_api_renderer end |
#search_columns ⇒ Object
The default search columns to use when generating search filters.
179 180 181 |
# File 'lib/rest_framework.rb', line 179 def search_columns @search_columns end |
#show_backtrace ⇒ Object
Whether the backtrace should be shown in rescued errors.
170 171 172 |
# File 'lib/rest_framework.rb', line 170 def show_backtrace @show_backtrace end |
#use_vendored_assets ⇒ Object
Option to use vendored assets (requires sprockets or propshaft) rather than linking to external assets (the default).
190 191 192 |
# File 'lib/rest_framework.rb', line 190 def use_vendored_assets @use_vendored_assets end |
#write_only_fields ⇒ Object
Returns the value of attribute write_only_fields.
183 184 185 |
# File 'lib/rest_framework.rb', line 183 def write_only_fields @write_only_fields end |