Class: ActiveScaffold::Config::Core
- Includes:
- Bridges::Ancestry::AncestryBridge, Bridges::DatePicker::DatePickerBridge, Bridges::FileColumn::FileColumnBridge, Bridges::PaperTrail::PaperTrailBridge, OrmChecks
- Defined in:
- lib/active_scaffold/config/core.rb
Overview
to fix the ckeditor bridge problem inherit from full class name
Defined Under Namespace
Classes: UserColumns, UserSettings
Constant Summary collapse
- @@plugin_directory =
File.(__FILE__).match(%{(^.*)/lib/active_scaffold/config/core.rb})[1]
- @@theme =
:default- @@cache_action_link_urls =
true- @@cache_action_links =
true- @@cache_association_options =
true- @@conditional_get_support =
false- @@store_user_settings =
true- @@action_links =
ActiveScaffold::DataStructures::ActionLinks.new
- @@custom_modules =
[]
- @@ignore_columns =
ActiveScaffold::DataStructures::Set.new
- @@sti_create_links =
true- @@timestamped_messages =
false- @@highlight_messages =
nil- @@after_config_callbacks =
[:_configure_sti]
Constants inherited from Base
Instance Attribute Summary collapse
-
#action_links ⇒ Object
readonly
action links are used by actions to tie together.
-
#actions ⇒ Object
provides read/write access to the local Actions DataStructure.
-
#cache_action_link_urls ⇒ Object
enable caching of action link urls.
-
#cache_action_links ⇒ Object
enable caching of action links.
-
#cache_association_options ⇒ Object
enable caching of association options.
-
#columns ⇒ Object
provides read/write access to the local Columns DataStructure.
-
#conditional_get_support ⇒ Object
enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views.
-
#custom_modules ⇒ Object
readonly
modules to include after all ActiveScaffold modules are included, to include generic customizations in some controllers These modules are included after the modules in global custom_modules setting.
-
#highlight_messages ⇒ Object
a hash of string (or array of strings) and highlighter string to highlight words in messages.
- #label(options = {}) ⇒ Object
-
#model_id ⇒ Object
readonly
some utility methods ——————–.
-
#sti_children ⇒ Object
STI children models, use an array of model names.
-
#sti_create_links ⇒ Object
lets you specify whether add a create link for each sti child for a specific controller.
-
#store_user_settings ⇒ Object
enable saving user settings in session (per_page, limit, page, sort, search params).
-
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller.
-
#timestamped_messages ⇒ Object
prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used.
Attributes included from Bridges::FileColumn::FileColumnBridge
Attributes inherited from Base
#action_group, #core, #formats, #user_settings_key
Class Method Summary collapse
- .actions=(val) ⇒ Object
-
.column ⇒ Object
access to default column configuration.
- .config_class(name) ⇒ Object
- .config_class?(name) ⇒ Boolean
- .freeze ⇒ Object
-
.ignore_columns ⇒ Object
columns that should be ignored for every model.
- .ignore_columns=(val) ⇒ Object
- .method_missing(name, *args) ⇒ Object
- .respond_to_missing?(name, include_all = false) ⇒ Boolean
-
.security ⇒ Object
access to the permissions configuration.
Instance Method Summary collapse
- #[](action_name) ⇒ Object
- #[]=(action_name, action_config) ⇒ Object
-
#_cache_lazy_values ⇒ Object
To be called before freezing.
-
#_configure_sti ⇒ Object
To be called after your finished configuration.
- #_setup_action(action) ⇒ Object
- #add_sti_create_links? ⇒ Boolean
- #build_action_columns(action, columns) ⇒ Object
-
#inherited_view_paths ⇒ Object
warning - this won’t work as a per-request dynamic attribute in rails 2.0.
-
#initialize(model_id) ⇒ Core
constructor
internal usage only below this point ————————————.
-
#method_missing(name, *args) ⇒ Object
configuration routing.
- #model ⇒ Object (also: #active_record_class)
- #primary_key ⇒ Object
- #respond_to_missing?(name, include_all = false) ⇒ Boolean
Methods included from OrmChecks
active_record?, #cast, cast, column_type, columns, columns_hash, content_columns, default_value, mongoid?, quoted_table_name, reflect_on_all_associations, table_name, tableless?, type_for_attribute
Methods included from Bridges::FileColumn::FileColumnBridge
Methods inherited from Base
inherited, #new_user_settings, #setup_user_setting_key, #user
Methods included from ActiveScaffold::Configurable
Constructor Details
#initialize(model_id) ⇒ Core
internal usage only below this point
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/active_scaffold/config/core.rb', line 171 def initialize(model_id) # rubocop:disable Lint/MissingSuper # model_id is the only absolutely required configuration value. it is also not publicly accessible. @model_id = model_id @custom_modules = [] setup_user_setting_key # inherit the actions list directly from the global level @actions = self.class.actions.clone # create a new default columns datastructure, since it doesn't make sense before now attribute_names = _columns.collect { |c| c.name.to_sym }.sort_by(&:to_s) association_column_names = _reflect_on_all_associations.collect { |a| a.name.to_sym } if defined?(ActiveMongoid) && model < ActiveMongoid::Associations association_column_names.concat model.am_relations.keys.map(&:to_sym) end @columns = ActiveScaffold::DataStructures::Columns.new(model, attribute_names + association_column_names.sort_by(&:to_s)) # and then, let's remove some columns from the inheritable set. content_columns = Set.new(_content_columns.map(&:name)) @columns.exclude(*self.class.ignore_columns) @columns.exclude(*@columns.find_all { |c| c.column && content_columns.exclude?(c.column.name) }.collect(&:name)) @columns.exclude(*model.reflect_on_all_associations.filter_map { |a| a.foreign_type.to_sym if a.[:polymorphic] }) @theme = self.class.theme @cache_action_link_urls = self.class.cache_action_link_urls @cache_action_links = self.class.cache_action_links = self.class. @conditional_get_support = self.class.conditional_get_support @store_user_settings = self.class.store_user_settings @sti_create_links = self.class.sti_create_links # inherit from the global set of action links @action_links = self.class.action_links.clone = self.class. = self.class. end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
configuration routing. we want to route calls named like an activated action to that action’s global or local Config class.
250 251 252 |
# File 'lib/active_scaffold/config/core.rb', line 250 def method_missing(name, *args) self[name] || super end |
Instance Attribute Details
#action_links ⇒ Object (readonly)
action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold.
149 150 151 |
# File 'lib/active_scaffold/config/core.rb', line 149 def action_links @action_links end |
#actions ⇒ Object
provides read/write access to the local Actions DataStructure
104 105 106 |
# File 'lib/active_scaffold/config/core.rb', line 104 def actions @actions end |
#cache_action_link_urls ⇒ Object
enable caching of action link urls
127 128 129 |
# File 'lib/active_scaffold/config/core.rb', line 127 def cache_action_link_urls @cache_action_link_urls end |
#cache_action_links ⇒ Object
enable caching of action links
130 131 132 |
# File 'lib/active_scaffold/config/core.rb', line 130 def cache_action_links @cache_action_links end |
#cache_association_options ⇒ Object
enable caching of association options
133 134 135 |
# File 'lib/active_scaffold/config/core.rb', line 133 def end |
#columns ⇒ Object
provides read/write access to the local Columns DataStructure
111 112 113 |
# File 'lib/active_scaffold/config/core.rb', line 111 def columns @columns end |
#conditional_get_support ⇒ Object
enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views
136 137 138 |
# File 'lib/active_scaffold/config/core.rb', line 136 def conditional_get_support @conditional_get_support end |
#custom_modules ⇒ Object (readonly)
modules to include after all ActiveScaffold modules are included, to include generic customizations in some controllers These modules are included after the modules in global custom_modules setting.
124 125 126 |
# File 'lib/active_scaffold/config/core.rb', line 124 def custom_modules @custom_modules end |
#highlight_messages ⇒ Object
a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
165 166 167 |
# File 'lib/active_scaffold/config/core.rb', line 165 def end |
#label(options = {}) ⇒ Object
154 155 156 |
# File 'lib/active_scaffold/config/core.rb', line 154 def label( = {}) as_(@label, ) || model.model_name.human(.merge([:count].to_i == 1 ? {} : {default: model.name.pluralize})) end |
#model_id ⇒ Object (readonly)
some utility methods
295 296 297 |
# File 'lib/active_scaffold/config/core.rb', line 295 def model_id @model_id end |
#sti_children ⇒ Object
STI children models, use an array of model names
159 160 161 |
# File 'lib/active_scaffold/config/core.rb', line 159 def sti_children @sti_children end |
#sti_create_links ⇒ Object
lets you specify whether add a create link for each sti child for a specific controller
142 143 144 |
# File 'lib/active_scaffold/config/core.rb', line 142 def sti_create_links @sti_create_links end |
#store_user_settings ⇒ Object
enable saving user settings in session (per_page, limit, page, sort, search params)
139 140 141 |
# File 'lib/active_scaffold/config/core.rb', line 139 def store_user_settings @store_user_settings end |
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller
120 121 122 |
# File 'lib/active_scaffold/config/core.rb', line 120 def theme @theme end |
#timestamped_messages ⇒ Object
prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
162 163 164 |
# File 'lib/active_scaffold/config/core.rb', line 162 def end |
Class Method Details
.actions=(val) ⇒ Object
13 14 15 |
# File 'lib/active_scaffold/config/core.rb', line 13 def self.actions=(val) @@actions = ActiveScaffold::DataStructures::Actions.new(*val) end |
.column ⇒ Object
access to default column configuration.
63 64 65 |
# File 'lib/active_scaffold/config/core.rb', line 63 def self.column ActiveScaffold::DataStructures::Column end |
.config_class(name) ⇒ Object
281 282 283 |
# File 'lib/active_scaffold/config/core.rb', line 281 def self.config_class(name) "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize if config_class?(name) end |
.config_class?(name) ⇒ Boolean
285 286 287 |
# File 'lib/active_scaffold/config/core.rb', line 285 def self.config_class?(name) ActiveScaffold::Config.const_defined? name.to_s.camelcase end |
.freeze ⇒ Object
94 95 96 97 98 |
# File 'lib/active_scaffold/config/core.rb', line 94 def self.freeze super security.freeze column.freeze end |
.ignore_columns ⇒ Object
columns that should be ignored for every model. these should be metadata columns like change dates, versions, etc. values in this array may be symbols or strings.
69 70 71 |
# File 'lib/active_scaffold/config/core.rb', line 69 def self.ignore_columns @@ignore_columns end |
.ignore_columns=(val) ⇒ Object
73 74 75 |
# File 'lib/active_scaffold/config/core.rb', line 73 def self.ignore_columns=(val) @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val) end |
.method_missing(name, *args) ⇒ Object
277 278 279 |
# File 'lib/active_scaffold/config/core.rb', line 277 def self.method_missing(name, *args) config_class(name) || super end |
.respond_to_missing?(name, include_all = false) ⇒ Boolean
289 290 291 |
# File 'lib/active_scaffold/config/core.rb', line 289 def self.respond_to_missing?(name, include_all = false) (config_class?(name) && @@actions.include?(name.to_s.underscore)) || super end |
.security ⇒ Object
access to the permissions configuration. configuration options include:
* current_user_method - what method on the controller returns the current user. default: :current_user
* - what the default is. default: true
58 59 60 |
# File 'lib/active_scaffold/config/core.rb', line 58 def self.security ActiveScaffold::ActiveRecordPermissions end |
Instance Method Details
#[](action_name) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/active_scaffold/config/core.rb', line 258 def [](action_name) klass = self.class.config_class(action_name) return unless klass underscored_name = action_name.to_s.underscore.to_sym unless @actions.include? underscored_name raise ArgumentError, "#{action_name.to_s.camelcase} is not enabled. Please enable it or remove any references in your configuration (e.g. config.#{underscored_name}.columns = [...])." end @action_configs ||= {} @action_configs[underscored_name] ||= klass.new(self) end |
#[]=(action_name, action_config) ⇒ Object
271 272 273 274 |
# File 'lib/active_scaffold/config/core.rb', line 271 def []=(action_name, action_config) @action_configs ||= {} @action_configs[action_name] = action_config end |
#_cache_lazy_values ⇒ Object
To be called before freezing
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/active_scaffold/config/core.rb', line 209 def _cache_lazy_values action_links.collection # ensure the collection group exist although it's empty action_links.member # ensure the collection group exist although it's empty if cache_action_link_urls || cache_action_links action_links.each(&:name_to_cache) list.filters.each { |filter| filter.each(&:name_to_cache) } if actions.include?(:list) end columns.select(&:sortable?).each(&:sort) columns.select(&:searchable?).each(&:search_sql) columns.each(&:field) actions.each do |action_name| action = send(action_name) Array(action.class.columns_collections).each { |method| action.send(method) } end end |
#_configure_sti ⇒ Object
To be called after your finished configuration
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/active_scaffold/config/core.rb', line 226 def _configure_sti return if sti_children.nil? column = model.inheritance_column if sti_create_links columns[column].form_ui ||= :hidden else columns[column].form_ui ||= :select columns[column]. ||= {} columns[column].[:options] = sti_children.collect do |model_name| [model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize] end end end |
#_setup_action(action) ⇒ Object
241 242 243 244 245 |
# File 'lib/active_scaffold/config/core.rb', line 241 def _setup_action(action) define_singleton_method action do self[action] end end |
#add_sti_create_links? ⇒ Boolean
144 145 146 |
# File 'lib/active_scaffold/config/core.rb', line 144 def add_sti_create_links? sti_create_links && !sti_children.nil? end |
#build_action_columns(action, columns) ⇒ Object
311 312 313 314 315 316 317 318 319 320 |
# File 'lib/active_scaffold/config/core.rb', line 311 def build_action_columns(action, columns) action_columns = if columns.is_a?(ActiveScaffold::DataStructures::ActionColumns) columns.dup else ActiveScaffold::DataStructures::ActionColumns.new(*columns) end action_columns.action = action.is_a?(Symbol) ? send(action) : action action_columns end |
#inherited_view_paths ⇒ Object
warning - this won’t work as a per-request dynamic attribute in rails 2.0. You’ll need to interact with Controller#generic_view_paths
307 308 309 |
# File 'lib/active_scaffold/config/core.rb', line 307 def inherited_view_paths @inherited_view_paths ||= [] end |
#model ⇒ Object Also known as: active_record_class
297 298 299 |
# File 'lib/active_scaffold/config/core.rb', line 297 def model @model ||= @model_id.to_s.camelize.constantize end |
#primary_key ⇒ Object
302 303 304 |
# File 'lib/active_scaffold/config/core.rb', line 302 def primary_key mongoid? ? '_id' : model.primary_key end |
#respond_to_missing?(name, include_all = false) ⇒ Boolean
254 255 256 |
# File 'lib/active_scaffold/config/core.rb', line 254 def respond_to_missing?(name, include_all = false) (self.class.config_class?(name) && @actions.include?(name.to_sym)) || super end |