Class: RESTFramework::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rest_framework.rb', line 161

def initialize
  self.register_api_renderer = 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

#inflect_acronymsObject

List of acronyms to be inflected in controller titles and field labels.



155
156
157
# File 'lib/rest_framework.rb', line 155

def inflect_acronyms
  @inflect_acronyms
end

#label_fieldsObject

The default label fields to use when generating labels for has_many associations.



145
146
147
# File 'lib/rest_framework.rb', line 145

def label_fields
  @label_fields
end

#large_reverse_association_tablesObject

Specify reverse association tables that are typically very large, and therefore should not be added to fields by default.



139
140
141
# File 'lib/rest_framework.rb', line 139

def large_reverse_association_tables
  @large_reverse_association_tables
end

#read_only_fieldsObject

Helper to set global read/write only fields.



151
152
153
# File 'lib/rest_framework.rb', line 151

def read_only_fields
  @read_only_fields
end

#register_api_rendererObject

Permits use of render(api: obj) syntax over render_api(obj); true by default.



135
136
137
# File 'lib/rest_framework.rb', line 135

def register_api_renderer
  @register_api_renderer
end

#search_columnsObject

The default search columns to use when generating search filters.



148
149
150
# File 'lib/rest_framework.rb', line 148

def search_columns
  @search_columns
end

#show_backtraceObject

Whether the backtrace should be shown in rescued errors.



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

def show_backtrace
  @show_backtrace
end

#use_vendored_assetsObject

Option to use vendored assets (requires sprockets or propshaft) rather than linking to external assets (the default).



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

def use_vendored_assets
  @use_vendored_assets
end

#write_only_fieldsObject

Returns the value of attribute write_only_fields.



152
153
154
# File 'lib/rest_framework.rb', line 152

def write_only_fields
  @write_only_fields
end