# File lib/active_scaffold/config/core.rb, line 290 def primary_key mongoid? ? '_id' : model.primary_key end
class ActiveScaffold::Config::Core
to fix the ckeditor bridge problem inherit from full class name
Attributes
action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold
.
provides read/write access to the local Actions
DataStructure
enable caching of action link urls
enable caching of association options
provides read/write access to the local Columns DataStructure
enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views
a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
a generally-applicable name for this ActiveScaffold
… will be used for generating page/section headers
some utility methods
STI children models, use an array of model names
lets you specify whether add a create link for each sti child for a specific controller
enable saving user settings in session (per_page, limit, page, sort, search params)
lets you override the global ActiveScaffold
theme for a specific controller
prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
Public Class Methods
Source
# File lib/active_scaffold/config/core.rb, line 10 def self.actions=(val) @@actions = ActiveScaffold::DataStructures::Actions.new(*val) end
Source
# File lib/active_scaffold/config/core.rb, line 60 def self.column ActiveScaffold::DataStructures::Column end
access to default column configuration.
Source
# File lib/active_scaffold/config/core.rb, line 269 def self.config_class(name) "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize if config_class?(name) end
Source
# File lib/active_scaffold/config/core.rb, line 273 def self.config_class?(name) ActiveScaffold::Config.const_defined? name.to_s.camelcase end
Source
# File lib/active_scaffold/config/core.rb, line 42 def self.dhtml_history? @@dhtml_history ? true : false end
Source
# File lib/active_scaffold/config/core.rb, line 91 def self.freeze super security.freeze column.freeze end
Source
# File lib/active_scaffold/config/core.rb, line 66 def self.ignore_columns @@ignore_columns end
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.
Source
# File lib/active_scaffold/config/core.rb, line 70 def self.ignore_columns=(val) @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val) end
Source
# File lib/active_scaffold/config/core.rb, line 265 def self.method_missing(name, *args) config_class(name) || super end
ActiveScaffold::Configurable#method_missing
Source
# File lib/active_scaffold/config/core.rb, line 161 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 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.options[:polymorphic] }) @theme = self.class.theme @cache_action_link_urls = self.class.cache_action_link_urls @cache_association_options = self.class.cache_association_options @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 @timestamped_messages = self.class.timestamped_messages @highlight_messages = self.class.highlight_messages end
internal usage only below this point
Source
# File lib/active_scaffold/config/core.rb, line 277 def self.respond_to_missing?(name, include_all = false) (config_class?(name) && @@actions.include?(name.to_s.underscore)) || super end
ActiveScaffold::Configurable#respond_to_missing?
Source
# File lib/active_scaffold/config/core.rb, line 55 def self.security ActiveScaffold::ActiveRecordPermissions end
access to the permissions configuration. configuration options include:
* current_user_method - what method on the controller returns the current user. default: :current_user * default_permission - what the default permission is. default: true
Public Instance Methods
Source
# File lib/active_scaffold/config/core.rb, line 246 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 "#{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
Source
# File lib/active_scaffold/config/core.rb, line 197 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 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
To be called before freezing
Source
# File lib/active_scaffold/config/core.rb, line 214 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].options ||= {} columns[column].options[:options] = sti_children.collect do |model_name| [model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize] end end end
To be called after your finished configuration
Source
# File lib/active_scaffold/config/core.rb, line 229 def _setup_action(action) define_singleton_method action do self[action] end end
Source
# File lib/active_scaffold/config/core.rb, line 103 def actions=(args) @actions = ActiveScaffold::DataStructures::Actions.new(*args) end
Source
# File lib/active_scaffold/config/core.rb, line 134 def add_sti_create_links? sti_create_links && !sti_children.nil? end
Source
# File lib/active_scaffold/config/core.rb, line 299 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
Source
# File lib/active_scaffold/config/core.rb, line 110 def columns=(val) @columns._inheritable = val.collect(&:to_sym) # Add virtual columns @columns.add(*val) end
Source
# File lib/active_scaffold/config/core.rb, line 295 def inherited_view_paths @inherited_view_paths ||= [] end
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
Source
# File lib/active_scaffold/config/core.rb, line 144 def label(options = {}) as_(@label, options) || model.model_name.human(options.merge(options[:count].to_i == 1 ? {} : {default: model.name.pluralize})) end
Source
# File lib/active_scaffold/config/core.rb, line 238 def method_missing(name, *args) self[name] || super end
configuration routing. we want to route calls named like an activated action to that action’s global or local Config
class.
ActiveScaffold::Configurable#method_missing
Source
# File lib/active_scaffold/config/core.rb, line 285 def model @model ||= @model_id.to_s.camelize.constantize end
Source
Source
# File lib/active_scaffold/config/core.rb, line 242 def respond_to_missing?(name, include_all = false) (self.class.config_class?(name) && @actions.include?(name.to_sym)) || super end
ActiveScaffold::Configurable#respond_to_missing?
Private Instance Methods
Source
# File lib/active_scaffold/config/core.rb, line 259 def []=(action_name, action_config) @action_configs ||= {} @action_configs[action_name] = action_config end