module ActiveScaffold
This module attempts to create permissions conventions for your models. It supports english-based methods that let you restrict access per-model, per-record, per-column, per-action, and per-user. All at once.
You may define instance methods in the following formats:
def #{column}_authorized_for_#{action}? def #{column}_authorized? def authorized_for_#{action}?
Public Class Methods
autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
click to toggle source
# File lib/active_scaffold.rb, line 24 def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__)) Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file| basename = File.basename(file, ".rb") mod.module_eval { autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}" } } end
exclude_bridges()
click to toggle source
# File lib/active_scaffold.rb, line 135 def self.exclude_bridges @@exclude_bridges ||= [] end
exclude_bridges=(bridges)
click to toggle source
exclude bridges you do not need name of bridge subdir should be used to exclude it eg
ActiveScaffold.exclude_bridges = [:cancan, :ancestry] if you are using Activescaffold as a gem add to initializer if you are using Activescaffold as a plugin add to active_scaffold_env.rb
# File lib/active_scaffold.rb, line 131 def self.exclude_bridges=(bridges) @@exclude_bridges = bridges end
included(base)
click to toggle source
# File lib/active_scaffold.rb, line 56 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? end
js_config()
click to toggle source
# File lib/active_scaffold.rb, line 121 def self.js_config @@js_config ||= {:scroll_on_close => true} end
js_config=(config)
click to toggle source
# File lib/active_scaffold.rb, line 117 def self.js_config=(config) @@js_config = config end
root()
click to toggle source
# File lib/active_scaffold.rb, line 139 def self.root File.dirname(__FILE__) + "/.." end
set_defaults(&block)
click to toggle source
# File lib/active_scaffold.rb, line 68 def self.set_defaults(&block) ActiveScaffold::Config::Core.configure &block end
Public Instance Methods
active_scaffold_config()
click to toggle source
# File lib/active_scaffold.rb, line 72 def active_scaffold_config self.class.active_scaffold_config end
active_scaffold_config_for(klass)
click to toggle source
# File lib/active_scaffold.rb, line 76 def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end
active_scaffold_session_storage(id = nil)
click to toggle source
# File lib/active_scaffold.rb, line 80 def active_scaffold_session_storage(id = nil) id ||= params[:eid] || "#{params[:controller]}#{"_#{nested.parent_id}" if nested?}" session_index = "as:#{id}" session[session_index] ||= {} session[session_index] end
check_input_device()
click to toggle source
# File lib/active_scaffold.rb, line 99 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
handle_user_settings()
click to toggle source
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.
# File lib/active_scaffold.rb, line 88 def handle_user_settings if self.class.uses_active_scaffold? 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 active_scaffold_session_storage[action_name] ||= {} conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params) end end end
hover_via_click?()
click to toggle source
# File lib/active_scaffold.rb, line 113 def hover_via_click? session[:hover_supported] == false end
touch_device?()
click to toggle source
# File lib/active_scaffold.rb, line 109 def touch_device? session[:input_device_type] == 'TOUCH' end