Class: ActionDispatch::Routing::Mapper::Resources::Resource

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

Overview

:nodoc:

Constant Summary

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Resource) initialize(entities, options = {})

A new instance of Resource



456
457
458
459
460
461
462
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 456

def initialize(entities, options = {})
  @name       = entities.to_s
  @path       = (options.delete(:path) || @name).to_s
  @controller = (options.delete(:controller) || @name).to_s
  @as         = options.delete(:as)
  @options    = options
end

Instance Attribute Details

- (Object) controller (readonly)

Returns the value of attribute controller



454
455
456
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 454

def controller
  @controller
end

- (Object) options (readonly)

Returns the value of attribute options



454
455
456
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 454

def options
  @options
end

- (Object) path (readonly) Also known as: collection_scope

Returns the value of attribute path



454
455
456
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 454

def path
  @path
end

Instance Method Details

- (Object) actions



468
469
470
471
472
473
474
475
476
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 468

def actions
  if only = @options[:only]
    Array(only).map(&:to_sym)
  elsif except = @options[:except]
    default_actions - Array(except).map(&:to_sym)
  else
    default_actions
  end
end

- (Object) collection_name

Checks for uncountable plurals, and appends "_index" if they're.



493
494
495
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 493

def collection_name
  singular == plural ? "#{plural}_index" : plural
end

- (Object) default_actions



464
465
466
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 464

def default_actions
  self.class::DEFAULT_ACTIONS
end

- (Object) member_scope



503
504
505
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 503

def member_scope
  "#{path}/:id"
end

- (Object) name



478
479
480
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 478

def name
  @as || @name
end

- (Object) nested_scope



511
512
513
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 511

def nested_scope
  "#{path}/:#{singular}_id"
end

- (Object) new_scope(new_path)



507
508
509
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 507

def new_scope(new_path)
  "#{path}/#{new_path}"
end

- (Object) plural



482
483
484
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 482

def plural
  @plural ||= name.to_s
end

- (Object) resource_scope



497
498
499
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 497

def resource_scope
  { :controller => controller }
end

- (Object) singular Also known as: member_name



486
487
488
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 486

def singular
  @singular ||= name.to_s.singularize
end