Class: ActionDispatch::Routing::DeprecatedMapper::Resource

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/routing/deprecated_mapper.rb

Overview

:nodoc:

Constant Summary

DEFAULT_ACTIONS =
:index, :create, :new, :edit, :show, :update, :destroy

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Resource) initialize(entities, options, defaults)

A new instance of Resource



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 219

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

Instance Attribute Details

- (Object) collection_methods (readonly)

Returns the value of attribute collection_methods



214
215
216
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 214

def collection_methods
  @collection_methods
end

- (Object) defaults (readonly)

Returns the value of attribute defaults



217
218
219
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 217

def defaults
  @defaults
end

- (Object) member_methods (readonly)

Returns the value of attribute member_methods



214
215
216
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 214

def member_methods
  @member_methods
end

- (Object) name_prefix (readonly)

Returns the value of attribute name_prefix



215
216
217
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 215

def name_prefix
  @name_prefix
end

- (Object) new_methods (readonly)

Returns the value of attribute new_methods



214
215
216
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 214

def new_methods
  @new_methods
end

- (Object) options (readonly)

Returns the value of attribute options



217
218
219
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 217

def options
  @options
end

- (Object) path_prefix (readonly)

Returns the value of attribute path_prefix



215
216
217
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 215

def path_prefix
  @path_prefix
end

- (Object) path_segment (readonly)

Returns the value of attribute path_segment



215
216
217
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 215

def path_segment
  @path_segment
end

- (Object) plural (readonly)

Returns the value of attribute plural



216
217
218
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 216

def plural
  @plural
end

- (Object) singular (readonly)

Returns the value of attribute singular



216
217
218
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 216

def singular
  @singular
end

Instance Method Details

- (Object) action_separator



278
279
280
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 278

def action_separator
  @action_separator ||= ActionController::Base.resource_action_separator
end

- (Object) conditions



244
245
246
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 244

def conditions
  @conditions ||= @options[:conditions] || {}
end

- (Object) controller



233
234
235
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 233

def controller
  @controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}"
end

- (Boolean) has_action?(action)

Returns:

  • (Boolean)


286
287
288
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 286

def has_action?(action)
  !DEFAULT_ACTIONS.include?(action) || action_allowed?(action)
end

- (Object) member_path



262
263
264
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 262

def member_path
  @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id"
end

- (Object) nesting_name_prefix



274
275
276
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 274

def nesting_name_prefix
  "#{shallow_name_prefix}#{singular}_"
end

- (Object) nesting_path_prefix



266
267
268
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 266

def nesting_path_prefix
  @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id"
end

- (Object) new_path



252
253
254
255
256
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 252

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

- (Object) path



248
249
250
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 248

def path
  @path ||= "#{path_prefix}/#{path_segment}"
end

- (Object) requirements(with_id = false)



237
238
239
240
241
242
# File 'actionpack/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

- (Object) shallow_name_prefix



270
271
272
# File 'actionpack/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

- (Object) shallow_path_prefix



258
259
260
# File 'actionpack/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

- (Boolean) uncountable?

Returns:

  • (Boolean)


282
283
284
# File 'actionpack/lib/action_dispatch/routing/deprecated_mapper.rb', line 282

def uncountable?
  @singular.to_s == @plural.to_s
end