module ActiveScaffold::Core::ClassMethods

Attributes

active_scaffold_config_block[R]

Public Instance Methods

active_scaffold(model_id = nil, &block) click to toggle source
# File lib/active_scaffold/core.rb, line 16
def active_scaffold(model_id = nil, &block)
  extend Prefixes
  # initialize bridges here
  ActiveScaffold::Bridges.run_all

  # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
  model_id = to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id

  # run the configuration
  @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
  @active_scaffold_config_block = block
  links_for_associations

  active_scaffold_superclasses_blocks.each { |superblock| active_scaffold_config.configure(&superblock) }
  active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
  active_scaffold_config.configure(&block) if block_given?
  active_scaffold_config._configure_sti unless active_scaffold_config.sti_children.nil?
  active_scaffold_config._load_action_columns

  # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
  klass = active_scaffold_config.model
  # Rails 4.0.4 has removed attribute_methods_generated,
  # and made define_attribute_methods threadsave to call multiple times.
  # Check for that here.
  if (Rails::VERSION::MAJOR == 4 && !klass.respond_to?(:attribute_methods_generated)) ||
     !klass.attribute_methods_generated?
    klass.define_attribute_methods
  end
  # include the rest of the code into the controller: the action core and the included actions
  module_eval do
    unless self < ActiveScaffold::Actions::Core
      include ActiveScaffold::Finder
      include ActiveScaffold::Constraints
      include ActiveScaffold::AttributeParams
      include ActiveScaffold::Actions::Core
    end
    active_scaffold_config.actions.each do |mod|
      include "ActiveScaffold::Actions::#{mod.to_s.camelize}".constantize
      mod_conf = active_scaffold_config.send(mod)
      next unless mod_conf.respond_to?(:link) && (link = mod_conf.link)

      # sneak the action links from the actions into the main set
      if link.is_a? Array
        link.each do |current_link|
          active_scaffold_config.action_links.add_to_group(current_link, active_scaffold_config.send(mod).action_group)
        end
      elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
        active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
      end
    end
  end
  _add_sti_create_links if active_scaffold_config.add_sti_create_links?
end
active_scaffold_config() click to toggle source
# File lib/active_scaffold/core.rb, line 149
def active_scaffold_config
  if @active_scaffold_config.nil?
    superclass.active_scaffold_config if superclass.respond_to? :active_scaffold_config
  else
    @active_scaffold_config
  end
end
active_scaffold_config_for(klass) click to toggle source
# File lib/active_scaffold/core.rb, line 169
def active_scaffold_config_for(klass)
  controller = active_scaffold_controller_for(klass)
rescue ActiveScaffold::ControllerNotFound
  config = ActiveScaffold::Config::Core.new(klass)
  config._load_action_columns
  config
else
  controller.active_scaffold_config
end
active_scaffold_controller_for(klass) click to toggle source
# File lib/active_scaffold/core.rb, line 179
def active_scaffold_controller_for(klass)
  return self if uses_active_scaffold? && klass == active_scaffold_config.model
  ActiveScaffold::Core.active_scaffold_controller_for(klass, to_s.deconstantize + '::')
end
active_scaffold_controller_for_column(column, options = {}) click to toggle source
# File lib/active_scaffold/core.rb, line 102
def active_scaffold_controller_for_column(column, options = {})
  if column.polymorphic_association?
    :polymorph
  elsif options.include?(:controller)
    "#{options[:controller].to_s.camelize}Controller".constantize
  else
    active_scaffold_controller_for(column.association.klass)
  end
rescue ActiveScaffold::ControllerNotFound
  nil
end
active_scaffold_superclasses_blocks() click to toggle source
# File lib/active_scaffold/core.rb, line 159
def active_scaffold_superclasses_blocks
  blocks = []
  klass = superclass
  while klass.respond_to? :active_scaffold_superclasses_blocks
    blocks << klass.active_scaffold_config_block
    klass = klass.superclass
  end
  blocks.compact.reverse
end
add_active_scaffold_path(path) click to toggle source
# File lib/active_scaffold/core.rb, line 139
def add_active_scaffold_path(path)
  as_path = File.realpath File.join(ActiveScaffold::Config::Core.plugin_directory, 'app', 'views')
  index = view_paths.find_index { |p| p.to_s == as_path }
  if index
    self.view_paths = view_paths[0..index - 1] + Array(path) + view_paths[index..-1]
  else
    append_view_path path
  end
end
uses_active_scaffold?() click to toggle source
# File lib/active_scaffold/core.rb, line 184
def uses_active_scaffold?
  !active_scaffold_config.nil?
end