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 1177

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

  valid_actions = self.class.default_actions(false) # ignore api_only for this validation
  if invalid_actions = invalid_only_except_options(options, valid_actions).presence
    raise ArgumentError, ":only and :except must include only #{valid_actions}, but also included #{invalid_actions}"
  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

Class Method Details

.default_actions(api_only)

[ GitHub ]

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

def default_actions(api_only)
  if api_only
    [:index, :create, :show, :update, :destroy]
  else
    [:index, :create, :new, :show, :update, :destroy, :edit]
  end
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 1175

attr_reader :controller, :path, :param

#param (readonly)

[ GitHub ]

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

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 1175

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 1199

def default_actions
  self.class.default_actions(@api_only)
end

#invalid_only_except_options(options, valid_actions) (private)

[ GitHub ]

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

def invalid_only_except_options(options, valid_actions)
  options.values_at(:only, :except).flatten.compact.uniq.map(&:to_sym) - valid_actions
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