module ActiveScaffold::Core

Public Class Methods

active_scaffold_controller_for(klass, controller_namespace = '::') click to toggle source

Tries to find a controller for the given ActiveRecord model. Searches in the namespace of the current controller for singular and plural versions of the conventional “#{model}Controller” syntax. You may override this method to customize the search routine.

# File lib/active_scaffold/core.rb, line 192
def self.active_scaffold_controller_for(klass, controller_namespace = '::')
  error_message = []
  class_names = [klass.to_s, klass.to_s.demodulize].map { |k| k.underscore.pluralize }.map { |k| [k, k.singularize] }.flatten
  [controller_namespace, ''].each do |namespace|
    class_names.each do |controller_name|
      begin
        controller = "#{namespace}#{controller_name.camelize}Controller".constantize
      rescue NameError => error
        # Only rescue NameError associated with the controller constant not existing - not other compile errors
        if error.message["uninitialized constant #{controller}"]
          error_message << "#{namespace}#{controller_name.camelize}Controller"
          next
        else
          raise
        end
      end
      raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold?
      raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model.to_s == klass.to_s
      return controller
    end
  end
  raise ActiveScaffold::ControllerNotFound, 'Could not find ' + error_message.join(' or '), caller
end
column_type_cast(value, column) click to toggle source
# File lib/active_scaffold/core.rb, line 216
def self.column_type_cast(value, column)
  if Rails.version < '4.2'
    column.type_cast value
  else
    column.type_cast_from_user value
  end
end
included(base) click to toggle source
# File lib/active_scaffold/core.rb, line 3
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

active_scaffold_config() click to toggle source
# File lib/active_scaffold/core.rb, line 7
def active_scaffold_config
  self.class.active_scaffold_config
end
active_scaffold_config_for(klass) click to toggle source
# File lib/active_scaffold/core.rb, line 11
def active_scaffold_config_for(klass)
  self.class.active_scaffold_config_for(klass)
end