Class: Avo::Configuration

Inherits:
Object
  • Object
show all
Includes:
ResourceConfiguration
Defined in:
lib/avo/configuration.rb,
lib/avo/configuration/resource_configuration.rb

Defined Under Namespace

Modules: ResourceConfiguration Classes: Branding

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourceConfiguration

#resource_controls_on_the_left?, #resource_controls_on_the_right?, #resource_controls_placement, #resource_controls_placement=

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



58
59
60
61
62
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
# File 'lib/avo/configuration.rb', line 58

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 {}
  @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
  @cache_resource_filters = false
  @context = proc {}
  @initial_breadcrumbs = proc {
    add_breadcrumb 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"
  @mount_avo_engines = true
  @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
end

Instance Attribute Details

#alert_dismiss_timeObject

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_nameObject



162
163
164
# File 'lib/avo/configuration.rb', line 162

def app_name
  Avo::ExecutionContext.new(target: @app_name).handle
end

#authenticateObject

Returns the value of attribute authenticate.



21
22
23
# File 'lib/avo/configuration.rb', line 21

def authenticate
  @authenticate
end

#authorization_clientObject

Returns the value of attribute authorization_client.



44
45
46
# File 'lib/avo/configuration.rb', line 44

def authorization_client
  @authorization_client
end

#authorization_methodsObject

Returns the value of attribute authorization_methods.



20
21
22
# File 'lib/avo/configuration.rb', line 20

def authorization_methods
  @authorization_methods
end

#brandingObject



158
159
160
# File 'lib/avo/configuration.rb', line 158

def branding
  Avo::Configuration::Branding.new(**@branding || {})
end

#buttons_on_form_footersObject

Returns the value of attribute buttons_on_form_footers.



39
40
41
# File 'lib/avo/configuration.rb', line 39

def buttons_on_form_footers
  @buttons_on_form_footers
end

#cache_resource_filtersObject

Returns the value of attribute cache_resource_filters.



27
28
29
# File 'lib/avo/configuration.rb', line 27

def cache_resource_filters
  @cache_resource_filters
end

#cache_resources_on_index_viewObject

Returns the value of attribute cache_resources_on_index_view.



26
27
28
# File 'lib/avo/configuration.rb', line 26

def cache_resources_on_index_view
  @cache_resources_on_index_view
end

#cache_storeObject



188
189
190
191
192
193
# File 'lib/avo/configuration.rb', line 188

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_recordObject

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

#contextObject

Returns the value of attribute context.



28
29
30
# File 'lib/avo/configuration.rb', line 28

def context
  @context
end

#currencyObject

Returns the value of attribute currency.



17
18
19
# File 'lib/avo/configuration.rb', line 17

def currency
  @currency
end

#current_userObject

Returns the value of attribute current_user.



22
23
24
# File 'lib/avo/configuration.rb', line 22

def current_user
  @current_user
end

#current_user_resource_nameObject

Returns the value of attribute current_user_resource_name.



36
37
38
# File 'lib/avo/configuration.rb', line 36

def current_user_resource_name
  @current_user_resource_name
end

#default_url_optionsObject

Returns the value of attribute default_url_options.



51
52
53
# File 'lib/avo/configuration.rb', line 51

def default_url_options
  @default_url_options
end

#default_view_typeObject

Returns the value of attribute default_view_type.



18
19
20
# File 'lib/avo/configuration.rb', line 18

def default_view_type
  @default_view_type
end

#disabled_featuresObject

Returns the value of attribute disabled_features.



38
39
40
# File 'lib/avo/configuration.rb', line 38

def disabled_features
  @disabled_features
end

#display_breadcrumbsObject

Returns the value of attribute display_breadcrumbs.



29
30
31
# File 'lib/avo/configuration.rb', line 29

def display_breadcrumbs
  @display_breadcrumbs
end

#display_license_request_timeout_errorObject

Returns the value of attribute display_license_request_timeout_error.



35
36
37
# File 'lib/avo/configuration.rb', line 35

def display_license_request_timeout_error
  @display_license_request_timeout_error
end

#field_wrapper_layoutObject

Returns the value of attribute field_wrapper_layout.



45
46
47
# File 'lib/avo/configuration.rb', line 45

def field_wrapper_layout
  @field_wrapper_layout
end

#full_width_containerObject

Returns the value of attribute full_width_container.



24
25
26
# File 'lib/avo/configuration.rb', line 24

def full_width_container
  @full_width_container
end

#full_width_index_viewObject

Returns the value of attribute full_width_index_view.



25
26
27
# File 'lib/avo/configuration.rb', line 25

def full_width_index_view
  @full_width_index_view
end

#hide_layout_when_printingObject

Returns the value of attribute hide_layout_when_printing.



30
31
32
# File 'lib/avo/configuration.rb', line 30

def hide_layout_when_printing
  @hide_layout_when_printing
end

#home_pathObject

Returns the value of attribute home_path.



32
33
34
# File 'lib/avo/configuration.rb', line 32

def home_path
  @home_path
end

Returns the value of attribute id_links_to_resource.



23
24
25
# File 'lib/avo/configuration.rb', line 23

def id_links_to_resource
  @id_links_to_resource
end

#initial_breadcrumbsObject

Returns the value of attribute initial_breadcrumbs.



31
32
33
# File 'lib/avo/configuration.rb', line 31

def initial_breadcrumbs
  @initial_breadcrumbs
end

#is_admin_methodObject

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_methodObject

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_keyObject

Returns the value of attribute license_key.



19
20
21
# File 'lib/avo/configuration.rb', line 19

def license_key
  @license_key
end

#localeObject

Returns the value of attribute locale.



16
17
18
# File 'lib/avo/configuration.rb', line 16

def locale
  @locale
end

#loggerObject



215
216
217
# File 'lib/avo/configuration.rb', line 215

def logger
  Avo::ExecutionContext.new(target: @logger).handle
end

Returns the value of attribute main_menu.



40
41
42
# File 'lib/avo/configuration.rb', line 40

def main_menu
  @main_menu
end

#model_resource_mappingObject

Returns the value of attribute model_resource_mapping.



42
43
44
# File 'lib/avo/configuration.rb', line 42

def model_resource_mapping
  @model_resource_mapping
end

#mount_avo_enginesObject

Returns the value of attribute mount_avo_engines.



50
51
52
# File 'lib/avo/configuration.rb', line 50

def mount_avo_engines
  @mount_avo_engines
end

#paginationObject



246
247
248
# File 'lib/avo/configuration.rb', line 246

def pagination
  Avo::ExecutionContext.new(target: @pagination).handle
end

#per_pageObject

Returns the value of attribute per_page.



13
14
15
# File 'lib/avo/configuration.rb', line 13

def per_page
  @per_page
end

#per_page_stepsObject

Returns the value of attribute per_page_steps.



14
15
16
# File 'lib/avo/configuration.rb', line 14

def per_page_steps
  @per_page_steps
end

#prefix_pathObject

Returns the value of attribute prefix_path.



48
49
50
# File 'lib/avo/configuration.rb', line 48

def prefix_path
  @prefix_path
end

#profile_menuObject

Returns the value of attribute profile_menu.



41
42
43
# File 'lib/avo/configuration.rb', line 41

def profile_menu
  @profile_menu
end

#raise_error_on_missing_policyObject

Returns the value of attribute raise_error_on_missing_policy.



37
38
39
# File 'lib/avo/configuration.rb', line 37

def raise_error_on_missing_policy
  @raise_error_on_missing_policy
end

#resource_default_viewObject

Returns the value of attribute resource_default_view.



43
44
45
# File 'lib/avo/configuration.rb', line 43

def resource_default_view
  @resource_default_view
end

#resource_parent_controllerObject

Returns the value of attribute resource_parent_controller.



49
50
51
# File 'lib/avo/configuration.rb', line 49

def resource_parent_controller
  @resource_parent_controller
end

#resourcesObject

Returns the value of attribute resources.



47
48
49
# File 'lib/avo/configuration.rb', line 47

def resources
  @resources
end

#root_pathObject



148
149
150
151
152
# File 'lib/avo/configuration.rb', line 148

def root_path
  return "" if @root_path === "/"

  @root_path
end

#search_debounceObject

Returns the value of attribute search_debounce.



33
34
35
# File 'lib/avo/configuration.rb', line 33

def search_debounce
  @search_debounce
end

#search_results_countObject

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_nameObject

Returns the value of attribute sign_out_path_name.



46
47
48
# File 'lib/avo/configuration.rb', line 46

def sign_out_path_name
  @sign_out_path_name
end

#timezoneObject

Returns the value of attribute timezone.



12
13
14
# File 'lib/avo/configuration.rb', line 12

def timezone
  @timezone
end

#turboObject



234
235
236
# File 'lib/avo/configuration.rb', line 234

def turbo
  Avo::ExecutionContext.new(target: @turbo).handle
end

#via_per_pageObject

Returns the value of attribute via_per_page.



15
16
17
# File 'lib/avo/configuration.rb', line 15

def via_per_page
  @via_per_page
end

#view_component_pathObject

Returns the value of attribute view_component_path.



34
35
36
# File 'lib/avo/configuration.rb', line 34

def view_component_path
  @view_component_path
end

Instance Method Details

#authenticate_with(&block) ⇒ Object



128
129
130
# File 'lib/avo/configuration.rb', line 128

def authenticate_with(&block)
  @authenticate = block if block.present?
end

#computed_cache_storeObject

When not in production or test we’ll just use the MemoryStore 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).



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/avo/configuration.rb', line 199

def computed_cache_store
  -> {
    if Rails.env.production?
      if Rails.cache.class.to_s.in?(production_rejected_cache_stores)
        ActiveSupport::Cache.lookup_store(:file_store, Rails.root.join("tmp", "cache"))
      else
        Rails.cache
      end
    elsif Rails.env.test?
      Rails.cache
    else
      ActiveSupport::Cache.lookup_store(:memory_store)
    end
  }
end

#current_user_method(&block) ⇒ Object



120
121
122
# File 'lib/avo/configuration.rb', line 120

def current_user_method(&block)
  @current_user = block if block.present?
end

#current_user_method=(method) ⇒ Object



124
125
126
# File 'lib/avo/configuration.rb', line 124

def current_user_method=(method)
  @current_user = method if method.present?
end

#default_localeObject



250
251
252
# File 'lib/avo/configuration.rb', line 250

def default_locale
  @locale || I18n.default_locale
end

#default_loggerObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/avo/configuration.rb', line 219

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_turboObject



238
239
240
241
242
243
244
# File 'lib/avo/configuration.rb', line 238

def default_turbo
  -> do
    {
      instant_click: true
    }
  end
end

#feature_enabled?(feature) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/avo/configuration.rb', line 154

def feature_enabled?(feature)
  !@disabled_features.map(&:to_sym).include?(feature.to_sym)
end

#licenseObject



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/avo/configuration.rb', line 172

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



166
167
168
169
170
# File 'lib/avo/configuration.rb', line 166

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

#namespaceObject



140
141
142
143
144
145
146
# File 'lib/avo/configuration.rb', line 140

def namespace
  if Avo.configuration.root_path.present?
    Avo.configuration.root_path.delete "/"
  else
    root_path.delete "/"
  end
end

#set_context(&block) ⇒ Object



132
133
134
# File 'lib/avo/configuration.rb', line 132

def set_context(&block)
  @context = block if block.present?
end

#set_initial_breadcrumbs(&block) ⇒ Object



136
137
138
# File 'lib/avo/configuration.rb', line 136

def set_initial_breadcrumbs(&block)
  @initial_breadcrumbs = block if block.present?
end