Module: ActiveScaffold::Core
- Defined in:
- lib/active_scaffold/core.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.active_scaffold_controller_for(klass, controller_namespace = '::') ⇒ Object
Tries to find a controller for the given ActiveRecord model.
- .column_type_cast(value, column) ⇒ Object
- .included(base) ⇒ Object
Instance Method Summary collapse
Class Method Details
.active_scaffold_controller_for(klass, controller_namespace = '::') ⇒ Object
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 “#modelController” syntax. You may override this method to customize the search routine.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/active_scaffold/core.rb', line 192 def self.active_scaffold_controller_for(klass, controller_namespace = '::') = [] 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.["uninitialized constant #{controller}"] << "#{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 ' + .join(' or '), caller end |
.column_type_cast(value, column) ⇒ Object
216 217 218 219 220 221 222 |
# 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) ⇒ Object
3 4 5 |
# File 'lib/active_scaffold/core.rb', line 3 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#active_scaffold_config ⇒ Object
7 8 9 |
# File 'lib/active_scaffold/core.rb', line 7 def active_scaffold_config self.class.active_scaffold_config end |
#active_scaffold_config_for(klass) ⇒ Object
11 12 13 |
# File 'lib/active_scaffold/core.rb', line 11 def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end |