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

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

Overview

:nodoc:

Direct Known Subclasses

SingletonResource

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, 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

#collection_methodsObject (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

#defaultsObject (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_methodsObject (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_prefixObject (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_methodsObject (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

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#path_prefixObject (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_segmentObject (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

#pluralObject (readonly)

Returns the value of attribute plural.



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

def plural
  @plural
end

#singularObject (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_separatorObject



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

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

#conditionsObject



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

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

#controllerObject



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

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

#has_action?(action) ⇒ Boolean

Returns:

  • (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_pathObject



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_prefixObject



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

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

#nesting_path_prefixObject



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_pathObject



252
253
254
255
256
# File '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

#pathObject



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_prefixObject



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_prefixObject



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

Returns:

  • (Boolean)


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

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