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.
- .included(base) ⇒ Object
Instance Method Summary collapse
- #active_scaffold_config ⇒ Object
- #active_scaffold_config_for(klass) ⇒ Object
- #active_scaffold_session_storage(id = nil) ⇒ Object
- #active_scaffold_session_storage_key(id = nil) ⇒ Object
- #check_input_device ⇒ Object
- #clear_storage ⇒ Object
-
#handle_user_settings ⇒ Object
at some point we need to pass the session and params into config.
- #hover_via_click? ⇒ Boolean
- #touch_device? ⇒ Boolean
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.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/active_scaffold/core.rb', line 254 def self.active_scaffold_controller_for(klass, controller_namespace = '::') = [] [controller_namespace, ''].each do |namespace| ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].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 |
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/active_scaffold/core.rb', line 3 def self.included(base) base.extend(ClassMethods) base.module_eval do # TODO: these should be in actions/core before_filter :handle_user_settings before_filter :check_input_device end base.helper_method :touch_device? base.helper_method :hover_via_click? base.helper_method :active_scaffold_constraints end |
Instance Method Details
#active_scaffold_config ⇒ Object
16 17 18 |
# File 'lib/active_scaffold/core.rb', line 16 def active_scaffold_config self.class.active_scaffold_config end |
#active_scaffold_config_for(klass) ⇒ Object
20 21 22 |
# File 'lib/active_scaffold/core.rb', line 20 def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end |
#active_scaffold_session_storage(id = nil) ⇒ Object
29 30 31 32 33 |
# File 'lib/active_scaffold/core.rb', line 29 def active_scaffold_session_storage(id = nil) session_index = active_scaffold_session_storage_key(id) session[session_index] ||= {} session[session_index] end |
#active_scaffold_session_storage_key(id = nil) ⇒ Object
24 25 26 27 |
# File 'lib/active_scaffold/core.rb', line 24 def active_scaffold_session_storage_key(id = nil) id ||= params[:eid] || "#{params[:controller]}#{"_#{nested_parent_id}" if nested?}" "as:#{id}" end |
#check_input_device ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/active_scaffold/core.rb', line 52 def check_input_device if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i] session[:input_device_type] = 'TOUCH' session[:hover_supported] = false else session[:input_device_type] = 'MOUSE' session[:hover_supported] = true end if session[:input_device_type].nil? end |
#clear_storage ⇒ Object
35 36 37 38 |
# File 'lib/active_scaffold/core.rb', line 35 def clear_storage session_index = active_scaffold_session_storage_key session.delete(session_index) unless session[session_index].present? end |
#handle_user_settings ⇒ Object
at some point we need to pass the session and params into config. we’ll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_scaffold/core.rb', line 41 def handle_user_settings if self.class.uses_active_scaffold? storage = active_scaffold_config.store_user_settings ? active_scaffold_session_storage : {} active_scaffold_config.actions.each do |action_name| conf_instance = active_scaffold_config.send(action_name) rescue next next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, storage, params) end end end |
#hover_via_click? ⇒ Boolean
66 67 68 |
# File 'lib/active_scaffold/core.rb', line 66 def hover_via_click? session[:hover_supported] == false end |
#touch_device? ⇒ Boolean
62 63 64 |
# File 'lib/active_scaffold/core.rb', line 62 def touch_device? session[:input_device_type] == 'TOUCH' end |