123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: actionpack/lib/action_dispatch/routing/mapper.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(entities, api_only, shallow, options = {}) ⇒ Resource

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1178

def initialize(entities, api_only, shallow, options = {})
  if options[:param].to_s.include?(":")
    raise ArgumentError, ":param option can't contain colons"
  end

  @name       = entities.to_s
  @path       = (options[:path] || @name).to_s
  @controller = (options[:controller] || @name).to_s
  @as         = options[:as]
  @param      = (options[:param] || :id).to_sym
  @options    = options
  @shallow    = shallow
  @api_only   = api_only
  @only       = options.delete :only
  @except     = options.delete :except
end

Instance Attribute Details

#collection_scope (readonly)

Alias for #path.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1243

alias :collection_scope :path

#controller (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1176

attr_reader :controller, :path, :param

#param (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1176

attr_reader :controller, :path, :param

#path (readonly) Also known as: #collection_scope, #member_scope, #nested_scope

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1176

attr_reader :controller, :path, :param

#shallow?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1263

def shallow?
  @shallow
end

#singleton?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1267

def singleton?; false; end

Instance Method Details

#actions

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1203

def actions
  if @except
    available_actions - Array(@except).map(&:to_sym)
  else
    available_actions
  end
end

#available_actions

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1211

def available_actions
  if @only
    Array(@only).map(&:to_sym)
  else
    default_actions
  end
end

#collection_name

Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1235

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

#default_actions

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1195

def default_actions
  if @api_only
    [:index, :create, :show, :update, :destroy]
  else
    [:index, :create, :new, :show, :update, :destroy, :edit]
  end
end

#member_name

Alias for #singular.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1231

alias :member_name :singular

#member_scope (readonly) Also known as: #shallow_scope

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1245

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

#name

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1219

def name
  @as || @name
end

#nested_param

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1255

def nested_param
  :"#{singular}_#{param}"
end

#nested_scope (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1259

def nested_scope
  "#{path}/:#{nested_param}"
end

#new_scope(new_path)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1251

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

#plural

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1223

def plural
  @plural ||= name.to_s
end

#resource_scope

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1239

def resource_scope
  controller
end

#shallow_scope

Alias for #member_scope.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1249

alias :shallow_scope :member_scope

#singular Also known as: #member_name

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1227

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