Class: ActionDispatch::Routing::DeprecatedMapper::Resource
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::DeprecatedMapper::Resource
- Defined in:
- lib/action_dispatch/routing/deprecated_mapper.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_ACTIONS =
:index, :create, :new, :edit, :show, :update, :destroy
Instance Attribute Summary collapse
-
#collection_methods ⇒ Object
readonly
Returns the value of attribute collection_methods.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#member_methods ⇒ Object
readonly
Returns the value of attribute member_methods.
-
#name_prefix ⇒ Object
readonly
Returns the value of attribute name_prefix.
-
#new_methods ⇒ Object
readonly
Returns the value of attribute new_methods.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path_prefix ⇒ Object
readonly
Returns the value of attribute path_prefix.
-
#path_segment ⇒ Object
readonly
Returns the value of attribute path_segment.
-
#plural ⇒ Object
readonly
Returns the value of attribute plural.
-
#singular ⇒ Object
readonly
Returns the value of attribute singular.
Instance Method Summary collapse
- #action_separator ⇒ Object
- #conditions ⇒ Object
- #controller ⇒ Object
- #has_action?(action) ⇒ Boolean
-
#initialize(entities, options, defaults) ⇒ Resource
constructor
A new instance of Resource.
- #member_path ⇒ Object
- #nesting_name_prefix ⇒ Object
- #nesting_path_prefix ⇒ Object
- #new_path ⇒ Object
- #path ⇒ Object
- #requirements(with_id = false) ⇒ Object
- #shallow_name_prefix ⇒ Object
- #shallow_path_prefix ⇒ Object
- #uncountable? ⇒ Boolean
Constructor Details
#initialize(entities, options, defaults) ⇒ Resource
Returns a new instance of Resource.
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 219 def initialize(entities, , defaults) @plural ||= entities @singular ||= [:singular] || plural.to_s.singularize @path_segment = .delete(:as) || @plural @options = @defaults = defaults arrange_actions add_default_actions set_allowed_actions set_prefixes end |
Instance Attribute Details
#collection_methods ⇒ Object (readonly)
Returns the value of attribute collection_methods.
214 215 216 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 214 def collection_methods @collection_methods end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
217 218 219 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 217 def defaults @defaults end |
#member_methods ⇒ Object (readonly)
Returns the value of attribute member_methods.
214 215 216 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 214 def member_methods @member_methods end |
#name_prefix ⇒ Object (readonly)
Returns the value of attribute name_prefix.
215 216 217 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 215 def name_prefix @name_prefix end |
#new_methods ⇒ Object (readonly)
Returns the value of attribute new_methods.
214 215 216 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 214 def new_methods @new_methods end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
217 218 219 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 217 def @options end |
#path_prefix ⇒ Object (readonly)
Returns the value of attribute path_prefix.
215 216 217 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 215 def path_prefix @path_prefix end |
#path_segment ⇒ Object (readonly)
Returns the value of attribute path_segment.
215 216 217 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 215 def path_segment @path_segment end |
#plural ⇒ Object (readonly)
Returns the value of attribute plural.
216 217 218 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 216 def plural @plural end |
#singular ⇒ Object (readonly)
Returns the value of attribute singular.
216 217 218 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 216 def singular @singular end |
Instance Method Details
#action_separator ⇒ Object
278 279 280 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 278 def action_separator @action_separator ||= ActionController::Base.resource_action_separator end |
#conditions ⇒ Object
244 245 246 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 244 def conditions @conditions ||= @options[:conditions] || {} end |
#controller ⇒ Object
233 234 235 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 233 def controller @controller ||= "#{[:namespace]}#{([:controller] || plural).to_s}" end |
#has_action?(action) ⇒ Boolean
286 287 288 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 286 def has_action?(action) !DEFAULT_ACTIONS.include?(action) || action_allowed?(action) end |
#member_path ⇒ Object
262 263 264 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 262 def member_path @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id" end |
#nesting_name_prefix ⇒ Object
274 275 276 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 274 def nesting_name_prefix "#{shallow_name_prefix}#{singular}_" end |
#nesting_path_prefix ⇒ Object
266 267 268 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 266 def nesting_path_prefix @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id" end |
#new_path ⇒ Object
252 253 254 255 256 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 252 def new_path new_action = self.[:path_names][:new] if self.[:path_names] new_action ||= self.defaults[:path_names][:new] @new_path ||= "#{path}/#{new_action}" end |
#path ⇒ Object
248 249 250 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 248 def path @path ||= "#{path_prefix}/#{path_segment}" end |
#requirements(with_id = false) ⇒ Object
237 238 239 240 241 242 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 237 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 |
#shallow_name_prefix ⇒ Object
270 271 272 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 270 def shallow_name_prefix @shallow_name_prefix ||= @options[:shallow] ? @options[:namespace].try(:gsub, /\//, '_') : name_prefix end |
#shallow_path_prefix ⇒ Object
258 259 260 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 258 def shallow_path_prefix @shallow_path_prefix ||= @options[:shallow] ? @options[:namespace].try(:sub, /\/$/, '') : path_prefix end |
#uncountable? ⇒ Boolean
282 283 284 |
# File 'lib/action_dispatch/routing/deprecated_mapper.rb', line 282 def uncountable? @singular.to_s == @plural.to_s end |