class ActionDispatch::Routing::DeprecatedMapper::Resource
:nodoc:
def action_allowed?(action)
def action_allowed?(action) only, except = @allowed_actions.values_at(:only, :except) (!only || only.include?(action)) && (!except || !except.include?(action)) end
def action_separator
def action_separator @action_separator ||= ActionController::Base.resource_action_separator end
def add_default_action(collection, method, action)
def add_default_action(collection, method, action) (collection[method] ||= []).unshift(action) end
def add_default_actions
def add_default_actions add_default_action(member_methods, :get, :edit) add_default_action(new_methods, :get, :new) end
def arrange_actions
def arrange_actions @collection_methods = arrange_actions_by_methods(options.delete(:collection)) @member_methods = arrange_actions_by_methods(options.delete(:member)) @new_methods = arrange_actions_by_methods(options.delete(:new)) end
def arrange_actions_by_methods(actions)
def arrange_actions_by_methods(actions) (actions || {}).inject({}) do |flipped_hash, (key, value)| (flipped_hash[value] ||= []) << key flipped_hash end end
def conditions
def conditions @conditions ||= @options[:conditions] || {} end
def controller
def controller @controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}" end
def has_action?(action)
def has_action?(action) !DEFAULT_ACTIONS.include?(action) || action_allowed?(action) end
def initialize(entities, options, defaults)
def initialize(entities, options, defaults) @plural ||= entities @singular ||= options[:singular] || plural.to_s.singularize @path_segment = options.delete(:as) || @plural @options = options @defaults = defaults arrange_actions add_default_actions set_allowed_actions set_prefixes end
def member_path
def member_path @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id" end
def nesting_name_prefix
def nesting_name_prefix "#{shallow_name_prefix}#{singular}_" end
def nesting_path_prefix
def nesting_path_prefix @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id" end
def new_path
def new_path new_action = self.options[:path_names][:new] if self.options[:path_names] new_action ||= self.defaults[:path_names][:new] @new_path ||= "#{path}/#{new_action}" end
def path
def path @path ||= "#{path_prefix}/#{path_segment}" end
def requirements(with_id = false)
def requirements(with_id = false) @requirements ||= @options[:requirements] || {} @id_requirement ||= { :id => @requirements.delete(:id) || /[^#{Routing::SEPARATORS.join}]+/ } with_id ? @requirements.merge(@id_requirement) : @requirements end
def set_allowed_actions
def set_allowed_actions only, except = @options.values_at(:only, :except) @allowed_actions ||= {} if only == :all || except == :none only = nil except = [] elsif only == :none || except == :all only = [] except = nil end if only @allowed_actions[:only] = Array(only).map {|a| a.to_sym } elsif except @allowed_actions[:except] = Array(except).map {|a| a.to_sym } end end
def set_prefixes
def set_prefixes @path_prefix = options.delete(:path_prefix) @name_prefix = options.delete(:name_prefix) end
def shallow_name_prefix
def shallow_name_prefix @shallow_name_prefix ||= @options[:shallow] ? @options[:namespace].try(:gsub, /\//, '_') : name_prefix end
def shallow_path_prefix
def shallow_path_prefix @shallow_path_prefix ||= @options[:shallow] ? @options[:namespace].try(:sub, /\/$/, '') : path_prefix end
def uncountable?
def uncountable? @singular.to_s == @plural.to_s end