Class: Avo::Configuration
- Inherits:
-
Object
- Object
- Avo::Configuration
- Defined in:
- lib/avo/configuration.rb
Defined Under Namespace
Classes: Branding
Constant Summary collapse
- RESOURCE_ROW_CONTROLS_CONFIG_DEFAULTS =
{ placement: :right, float: false, show_on_hover: false }.freeze
Instance Attribute Summary collapse
-
#alert_dismiss_time ⇒ Object
Returns the value of attribute alert_dismiss_time.
- #app_name ⇒ Object
-
#associations_lookup_list_limit ⇒ Object
Returns the value of attribute associations_lookup_list_limit.
-
#authenticate ⇒ Object
Returns the value of attribute authenticate.
-
#authorization_client ⇒ Object
Returns the value of attribute authorization_client.
-
#authorization_methods ⇒ Object
Returns the value of attribute authorization_methods.
- #branding ⇒ Object
-
#buttons_on_form_footers ⇒ Object
Returns the value of attribute buttons_on_form_footers.
-
#cache_resources_on_index_view ⇒ Object
Returns the value of attribute cache_resources_on_index_view.
- #cache_store ⇒ Object
-
#click_row_to_view_record ⇒ Object
Returns the value of attribute click_row_to_view_record.
-
#column_names_mapping ⇒ Object
Returns the value of attribute column_names_mapping.
-
#column_types_mapping ⇒ Object
Returns the value of attribute column_types_mapping.
-
#context ⇒ Object
Returns the value of attribute context.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#current_user_resource_name ⇒ Object
Returns the value of attribute current_user_resource_name.
-
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
-
#default_view_type ⇒ Object
Returns the value of attribute default_view_type.
- #disabled_features ⇒ Object
-
#display_breadcrumbs ⇒ Object
Returns the value of attribute display_breadcrumbs.
-
#display_license_request_timeout_error ⇒ Object
Returns the value of attribute display_license_request_timeout_error.
- #exclude_from_status ⇒ Object
- #explicit_authorization ⇒ Object
-
#field_wrapper_layout ⇒ Object
Returns the value of attribute field_wrapper_layout.
-
#first_sorting_option ⇒ Object
Returns the value of attribute first_sorting_option.
-
#full_width_container ⇒ Object
Returns the value of attribute full_width_container.
-
#full_width_index_view ⇒ Object
Returns the value of attribute full_width_index_view.
-
#hide_layout_when_printing ⇒ Object
Returns the value of attribute hide_layout_when_printing.
-
#home_path ⇒ Object
Returns the value of attribute home_path.
-
#id_links_to_resource ⇒ Object
Returns the value of attribute id_links_to_resource.
-
#initial_breadcrumbs ⇒ Object
Returns the value of attribute initial_breadcrumbs.
-
#is_admin_method ⇒ Object
Returns the value of attribute is_admin_method.
-
#is_developer_method ⇒ Object
Returns the value of attribute is_developer_method.
-
#license_key ⇒ Object
Returns the value of attribute license_key.
-
#locale ⇒ Object
Returns the value of attribute locale.
- #logger ⇒ Object
-
#main_menu ⇒ Object
Returns the value of attribute main_menu.
-
#model_generator_hook ⇒ Object
Returns the value of attribute model_generator_hook.
-
#model_resource_mapping ⇒ Object
Returns the value of attribute model_resource_mapping.
- #pagination ⇒ Object
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#per_page_steps ⇒ Object
Returns the value of attribute per_page_steps.
- #persistence ⇒ Object
-
#prefix_path ⇒ Object
Returns the value of attribute prefix_path.
-
#profile_menu ⇒ Object
Returns the value of attribute profile_menu.
-
#raise_error_on_missing_policy ⇒ Object
Returns the value of attribute raise_error_on_missing_policy.
-
#resource_default_view ⇒ Object
Returns the value of attribute resource_default_view.
-
#resource_parent_controller ⇒ Object
Returns the value of attribute resource_parent_controller.
- #resource_row_controls_config ⇒ Object
-
#resources ⇒ Object
Returns the value of attribute resources.
- #root_path ⇒ Object
-
#search_debounce ⇒ Object
Returns the value of attribute search_debounce.
-
#search_results_count ⇒ Object
Returns the value of attribute search_results_count.
-
#sign_out_path_name ⇒ Object
Returns the value of attribute sign_out_path_name.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
- #turbo ⇒ Object
-
#via_per_page ⇒ Object
Returns the value of attribute via_per_page.
-
#view_component_path ⇒ Object
Returns the value of attribute view_component_path.
Instance Method Summary collapse
- #authenticate_with(&block) ⇒ Object
-
#authorization_enabled? ⇒ Boolean
Authorization is enabled when: (avo-pro gem is installed) AND (authorization_client is NOT nil).
- #clear_license_response_on_deploy=(value) ⇒ Object
-
#computed_cache_store ⇒ Object
When not in production or test we’ll just use the FileStore which is good enough.
- #current_user_method(&block) ⇒ Object
- #current_user_method=(method) ⇒ Object
- #default_locale ⇒ Object
- #default_logger ⇒ Object
- #default_turbo ⇒ Object
- #feature_enabled?(feature) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #license ⇒ Object
- #license=(value) ⇒ Object
- #mount_avo_engines= ⇒ Object
- #namespace ⇒ Object
- #session_persistence_enabled? ⇒ Boolean
- #set_context(&block) ⇒ Object
- #set_initial_breadcrumbs(&block) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/avo/configuration.rb', line 63 def initialize @root_path = "/avo" @app_name = ::Rails.application.class.to_s.split("::").first.underscore.humanize(keep_id_suffix: true) @timezone = "UTC" @per_page = 24 @per_page_steps = [12, 24, 48, 72] @via_per_page = 8 @locale = nil @currency = "USD" @default_view_type = :table @license_key = nil @current_user = proc {} @authenticate = proc {} @explicit_authorization = false @authorization_methods = { index: "index?", show: "show?", edit: "edit?", new: "new?", update: "update?", create: "create?", destroy: "destroy?" } @id_links_to_resource = false @full_width_container = false @full_width_index_view = false @cache_resources_on_index_view = Avo::PACKED @persistence = { driver: nil } @context = proc {} @initial_breadcrumbs = proc { I18n.t("avo.home").humanize, avo.root_path } @display_breadcrumbs = true @hide_layout_when_printing = false @home_path = nil @search_debounce = 300 @view_component_path = "app/components" @display_license_request_timeout_error = true @current_user_resource_name = "user" @raise_error_on_missing_policy = false @disabled_features = [] @buttons_on_form_footers = false @main_menu = nil @profile_menu = nil @model_resource_mapping = {} @resource_default_view = Avo::ViewInquirer.new("show") @authorization_client = :pundit @field_wrapper_layout = :inline @resources = nil @resource_parent_controller = "Avo::ResourcesController" @cache_store = computed_cache_store @logger = default_logger @turbo = default_turbo @default_url_options = [] @pagination = {} @click_row_to_view_record = false @alert_dismiss_time = 5000 @is_admin_method = :is_admin? @is_developer_method = :is_developer? @search_results_count = 8 @first_sorting_option = :desc # :desc or :asc @associations_lookup_list_limit = 1000 @exclude_from_status = [] @column_names_mapping = {} @column_types_mapping = {} @resource_row_controls_config = {} @model_generator_hook = true end |
Instance Attribute Details
#alert_dismiss_time ⇒ Object
Returns the value of attribute alert_dismiss_time.
53 54 55 |
# File 'lib/avo/configuration.rb', line 53 def alert_dismiss_time @alert_dismiss_time end |
#app_name ⇒ Object
198 199 200 |
# File 'lib/avo/configuration.rb', line 198 def app_name Avo::ExecutionContext.new(target: @app_name).handle end |
#associations_lookup_list_limit ⇒ Object
Returns the value of attribute associations_lookup_list_limit.
58 59 60 |
# File 'lib/avo/configuration.rb', line 58 def associations_lookup_list_limit @associations_lookup_list_limit end |
#authenticate ⇒ Object
Returns the value of attribute authenticate.
23 24 25 |
# File 'lib/avo/configuration.rb', line 23 def authenticate @authenticate end |
#authorization_client ⇒ Object
Returns the value of attribute authorization_client.
45 46 47 |
# File 'lib/avo/configuration.rb', line 45 def @authorization_client end |
#authorization_methods ⇒ Object
Returns the value of attribute authorization_methods.
22 23 24 |
# File 'lib/avo/configuration.rb', line 22 def @authorization_methods end |
#branding ⇒ Object
194 195 196 |
# File 'lib/avo/configuration.rb', line 194 def branding Avo::Configuration::Branding.new(**@branding || {}) end |
#buttons_on_form_footers ⇒ Object
Returns the value of attribute buttons_on_form_footers.
40 41 42 |
# File 'lib/avo/configuration.rb', line 40 def @buttons_on_form_footers end |
#cache_resources_on_index_view ⇒ Object
Returns the value of attribute cache_resources_on_index_view.
28 29 30 |
# File 'lib/avo/configuration.rb', line 28 def cache_resources_on_index_view @cache_resources_on_index_view end |
#cache_store ⇒ Object
230 231 232 233 234 235 |
# File 'lib/avo/configuration.rb', line 230 def cache_store Avo::ExecutionContext.new( target: @cache_store, production_rejected_cache_stores: %w[ActiveSupport::Cache::MemoryStore ActiveSupport::Cache::NullStore] ).handle end |
#click_row_to_view_record ⇒ Object
Returns the value of attribute click_row_to_view_record.
52 53 54 |
# File 'lib/avo/configuration.rb', line 52 def click_row_to_view_record @click_row_to_view_record end |
#column_names_mapping ⇒ Object
Returns the value of attribute column_names_mapping.
59 60 61 |
# File 'lib/avo/configuration.rb', line 59 def column_names_mapping @column_names_mapping end |
#column_types_mapping ⇒ Object
Returns the value of attribute column_types_mapping.
60 61 62 |
# File 'lib/avo/configuration.rb', line 60 def column_types_mapping @column_types_mapping end |
#context ⇒ Object
Returns the value of attribute context.
29 30 31 |
# File 'lib/avo/configuration.rb', line 29 def context @context end |
#currency ⇒ Object
Returns the value of attribute currency.
19 20 21 |
# File 'lib/avo/configuration.rb', line 19 def currency @currency end |
#current_user ⇒ Object
Returns the value of attribute current_user.
24 25 26 |
# File 'lib/avo/configuration.rb', line 24 def current_user @current_user end |
#current_user_resource_name ⇒ Object
Returns the value of attribute current_user_resource_name.
37 38 39 |
# File 'lib/avo/configuration.rb', line 37 def current_user_resource_name @current_user_resource_name end |
#default_url_options ⇒ Object
Returns the value of attribute default_url_options.
51 52 53 |
# File 'lib/avo/configuration.rb', line 51 def @default_url_options end |
#default_view_type ⇒ Object
Returns the value of attribute default_view_type.
20 21 22 |
# File 'lib/avo/configuration.rb', line 20 def default_view_type @default_view_type end |
#disabled_features ⇒ Object
186 187 188 |
# File 'lib/avo/configuration.rb', line 186 def disabled_features Avo::ExecutionContext.new(target: @disabled_features).handle end |
#display_breadcrumbs ⇒ Object
Returns the value of attribute display_breadcrumbs.
30 31 32 |
# File 'lib/avo/configuration.rb', line 30 def @display_breadcrumbs end |
#display_license_request_timeout_error ⇒ Object
Returns the value of attribute display_license_request_timeout_error.
36 37 38 |
# File 'lib/avo/configuration.rb', line 36 def display_license_request_timeout_error @display_license_request_timeout_error end |
#exclude_from_status ⇒ Object
282 283 284 |
# File 'lib/avo/configuration.rb', line 282 def exclude_from_status Avo::ExecutionContext.new(target: @exclude_from_status).handle end |
#explicit_authorization ⇒ Object
302 303 304 |
# File 'lib/avo/configuration.rb', line 302 def Avo::ExecutionContext.new(target: @explicit_authorization).handle end |
#field_wrapper_layout ⇒ Object
Returns the value of attribute field_wrapper_layout.
46 47 48 |
# File 'lib/avo/configuration.rb', line 46 def field_wrapper_layout @field_wrapper_layout end |
#first_sorting_option ⇒ Object
Returns the value of attribute first_sorting_option.
57 58 59 |
# File 'lib/avo/configuration.rb', line 57 def first_sorting_option @first_sorting_option end |
#full_width_container ⇒ Object
Returns the value of attribute full_width_container.
26 27 28 |
# File 'lib/avo/configuration.rb', line 26 def full_width_container @full_width_container end |
#full_width_index_view ⇒ Object
Returns the value of attribute full_width_index_view.
27 28 29 |
# File 'lib/avo/configuration.rb', line 27 def full_width_index_view @full_width_index_view end |
#hide_layout_when_printing ⇒ Object
Returns the value of attribute hide_layout_when_printing.
31 32 33 |
# File 'lib/avo/configuration.rb', line 31 def hide_layout_when_printing @hide_layout_when_printing end |
#home_path ⇒ Object
Returns the value of attribute home_path.
33 34 35 |
# File 'lib/avo/configuration.rb', line 33 def home_path @home_path end |
#id_links_to_resource ⇒ Object
Returns the value of attribute id_links_to_resource.
25 26 27 |
# File 'lib/avo/configuration.rb', line 25 def id_links_to_resource @id_links_to_resource end |
#initial_breadcrumbs ⇒ Object
Returns the value of attribute initial_breadcrumbs.
32 33 34 |
# File 'lib/avo/configuration.rb', line 32 def @initial_breadcrumbs end |
#is_admin_method ⇒ Object
Returns the value of attribute is_admin_method.
54 55 56 |
# File 'lib/avo/configuration.rb', line 54 def is_admin_method @is_admin_method end |
#is_developer_method ⇒ Object
Returns the value of attribute is_developer_method.
55 56 57 |
# File 'lib/avo/configuration.rb', line 55 def is_developer_method @is_developer_method end |
#license_key ⇒ Object
Returns the value of attribute license_key.
21 22 23 |
# File 'lib/avo/configuration.rb', line 21 def license_key @license_key end |
#locale ⇒ Object
Returns the value of attribute locale.
18 19 20 |
# File 'lib/avo/configuration.rb', line 18 def locale @locale end |
#logger ⇒ Object
259 260 261 |
# File 'lib/avo/configuration.rb', line 259 def logger Avo::ExecutionContext.new(target: @logger).handle end |
#main_menu ⇒ Object
Returns the value of attribute main_menu.
41 42 43 |
# File 'lib/avo/configuration.rb', line 41 def @main_menu end |
#model_generator_hook ⇒ Object
Returns the value of attribute model_generator_hook.
61 62 63 |
# File 'lib/avo/configuration.rb', line 61 def model_generator_hook @model_generator_hook end |
#model_resource_mapping ⇒ Object
Returns the value of attribute model_resource_mapping.
43 44 45 |
# File 'lib/avo/configuration.rb', line 43 def model_resource_mapping @model_resource_mapping end |
#pagination ⇒ Object
294 295 296 |
# File 'lib/avo/configuration.rb', line 294 def pagination Avo::ExecutionContext.new(target: @pagination).handle end |
#per_page ⇒ Object
Returns the value of attribute per_page.
15 16 17 |
# File 'lib/avo/configuration.rb', line 15 def per_page @per_page end |
#per_page_steps ⇒ Object
Returns the value of attribute per_page_steps.
16 17 18 |
# File 'lib/avo/configuration.rb', line 16 def per_page_steps @per_page_steps end |
#persistence ⇒ Object
306 307 308 |
# File 'lib/avo/configuration.rb', line 306 def persistence Avo::ExecutionContext.new(target: @persistence).handle end |
#prefix_path ⇒ Object
Returns the value of attribute prefix_path.
49 50 51 |
# File 'lib/avo/configuration.rb', line 49 def prefix_path @prefix_path end |
#profile_menu ⇒ Object
Returns the value of attribute profile_menu.
42 43 44 |
# File 'lib/avo/configuration.rb', line 42 def @profile_menu end |
#raise_error_on_missing_policy ⇒ Object
Returns the value of attribute raise_error_on_missing_policy.
38 39 40 |
# File 'lib/avo/configuration.rb', line 38 def raise_error_on_missing_policy @raise_error_on_missing_policy end |
#resource_default_view ⇒ Object
Returns the value of attribute resource_default_view.
44 45 46 |
# File 'lib/avo/configuration.rb', line 44 def resource_default_view @resource_default_view end |
#resource_parent_controller ⇒ Object
Returns the value of attribute resource_parent_controller.
50 51 52 |
# File 'lib/avo/configuration.rb', line 50 def resource_parent_controller @resource_parent_controller end |
#resource_row_controls_config ⇒ Object
142 143 144 |
# File 'lib/avo/configuration.rb', line 142 def resource_row_controls_config RESOURCE_ROW_CONTROLS_CONFIG_DEFAULTS.merge @resource_row_controls_config end |
#resources ⇒ Object
Returns the value of attribute resources.
48 49 50 |
# File 'lib/avo/configuration.rb', line 48 def resources @resources end |
#root_path ⇒ Object
180 181 182 183 184 |
# File 'lib/avo/configuration.rb', line 180 def root_path return "" if @root_path === "/" @root_path end |
#search_debounce ⇒ Object
Returns the value of attribute search_debounce.
34 35 36 |
# File 'lib/avo/configuration.rb', line 34 def search_debounce @search_debounce end |
#search_results_count ⇒ Object
Returns the value of attribute search_results_count.
56 57 58 |
# File 'lib/avo/configuration.rb', line 56 def search_results_count @search_results_count end |
#sign_out_path_name ⇒ Object
Returns the value of attribute sign_out_path_name.
47 48 49 |
# File 'lib/avo/configuration.rb', line 47 def sign_out_path_name @sign_out_path_name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
14 15 16 |
# File 'lib/avo/configuration.rb', line 14 def timezone @timezone end |
#turbo ⇒ Object
278 279 280 |
# File 'lib/avo/configuration.rb', line 278 def turbo Avo::ExecutionContext.new(target: @turbo).handle end |
#via_per_page ⇒ Object
Returns the value of attribute via_per_page.
17 18 19 |
# File 'lib/avo/configuration.rb', line 17 def via_per_page @via_per_page end |
#view_component_path ⇒ Object
Returns the value of attribute view_component_path.
35 36 37 |
# File 'lib/avo/configuration.rb', line 35 def view_component_path @view_component_path end |
Instance Method Details
#authenticate_with(&block) ⇒ Object
160 161 162 |
# File 'lib/avo/configuration.rb', line 160 def authenticate_with(&block) @authenticate = block if block.present? end |
#authorization_enabled? ⇒ Boolean
Authorization is enabled when: (avo-pro gem is installed) AND (authorization_client is NOT nil)
148 149 150 |
# File 'lib/avo/configuration.rb', line 148 def @authorization_enabled ||= Avo.plugin_manager.installed?("avo-pro") && !.nil? end |
#clear_license_response_on_deploy=(value) ⇒ Object
208 209 210 211 212 |
# File 'lib/avo/configuration.rb', line 208 def clear_license_response_on_deploy=(value) if Rails.env.development? puts "[Avo DEPRECATION WARNING]: The `config.clear_license_response_on_deploy` configuration option is deprecated and will be removed in future versions. Please discontinue its use, no extra action is needed." end end |
#computed_cache_store ⇒ Object
When not in production or test we’ll just use the FileStore which is good enough. When running in production we’ll use Rails.cache if it’s not ActiveSupport::Cache::MemoryStore or ActiveSupport::Cache::NullStore. If it’s one of rejected cache stores, we’ll use the FileStore. We decided against the MemoryStore in production because it will not be shared between multiple processes (when using Puma).
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/avo/configuration.rb', line 241 def computed_cache_store file_store_instance = ActiveSupport::Cache.lookup_store(:file_store, Rails.root.join("tmp", "cache")) -> { if Rails.env.production? if Rails.cache.class.to_s.in?(production_rejected_cache_stores) file_store_instance else Rails.cache end elsif Rails.env.test? Rails.cache else file_store_instance end } end |
#current_user_method(&block) ⇒ Object
152 153 154 |
# File 'lib/avo/configuration.rb', line 152 def current_user_method(&block) @current_user = block if block.present? end |
#current_user_method=(method) ⇒ Object
156 157 158 |
# File 'lib/avo/configuration.rb', line 156 def current_user_method=(method) @current_user = method if method.present? end |
#default_locale ⇒ Object
298 299 300 |
# File 'lib/avo/configuration.rb', line 298 def default_locale @locale || I18n.default_locale end |
#default_logger ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/avo/configuration.rb', line 263 def default_logger -> { file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log")) file_logger.datetime_format = "%Y-%m-%d %H:%M:%S" file_logger.formatter = proc do |severity, time, progname, msg| "[Avo->] #{time}: #{msg}\n".tap do |i| puts i end end file_logger } end |
#default_turbo ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/avo/configuration.rb', line 286 def default_turbo -> do { instant_click: true } end end |
#feature_enabled?(feature) ⇒ Boolean
190 191 192 |
# File 'lib/avo/configuration.rb', line 190 def feature_enabled?(feature) !disabled_features.map(&:to_sym).include?(feature.to_sym) end |
#license ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/avo/configuration.rb', line 214 def license gems = Gem::Specification.map {|gem| gem.name} @license ||= if gems.include?("avo-advanced") "advanced" elsif gems.include?("avo-pro") "pro" elsif gems.include?("avo") "community" end end |
#license=(value) ⇒ Object
202 203 204 205 206 |
# File 'lib/avo/configuration.rb', line 202 def license=(value) if Rails.env.development? puts "[Avo DEPRECATION WARNING]: The `config.license` configuration option is no longer supported and will be removed in future versions. Please discontinue its use and solely utilize the `license_key` instead." end end |
#mount_avo_engines= ⇒ Object
314 315 316 317 318 |
# File 'lib/avo/configuration.rb', line 314 def mount_avo_engines=(...) raise "'mount_avo_engines' option is now obsolete. \n" \ "Please refer to the upgrade guide for details on the new mounting point: \n" \ "https://docs.avohq.io/3.0/upgrade.html#Avo's%20mounting%20point%20update" end |
#namespace ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/avo/configuration.rb', line 172 def namespace if Avo.configuration.root_path.present? Avo.configuration.root_path.delete "/" else root_path.delete "/" end end |
#session_persistence_enabled? ⇒ Boolean
310 311 312 |
# File 'lib/avo/configuration.rb', line 310 def session_persistence_enabled? persistence[:driver] == :session end |
#set_context(&block) ⇒ Object
164 165 166 |
# File 'lib/avo/configuration.rb', line 164 def set_context(&block) @context = block if block.present? end |
#set_initial_breadcrumbs(&block) ⇒ Object
168 169 170 |
# File 'lib/avo/configuration.rb', line 168 def (&block) @initial_breadcrumbs = block if block.present? end |