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, only: nil, except: nil, **options) ⇒ Resource

[ GitHub ]

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

def initialize(entities, api_only, shallow, only: nil, except: nil, **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(valid_actions, only:, except:).presence)
    error_prefix = "Route `resource#{"s" unless singleton?} :#{entities}`"
    raise ArgumentError, "#{error_prefix} - :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       = only
  @except     = except
end

Class Method Details

.default_actions(api_only)

[ GitHub ]

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

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 1386

alias :collection_scope :path

#controller (readonly)

[ GitHub ]

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

attr_reader :controller, :path, :param

#param (readonly)

[ GitHub ]

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

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 1317

attr_reader :controller, :path, :param

#shallow?Boolean (readonly)

[ GitHub ]

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

def shallow?
  @shallow
end

#singleton?Boolean (readonly)

[ GitHub ]

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

def singleton?; false; end

Instance Method Details

#actions

[ GitHub ]

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

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 1354

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 1378

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

#default_actions

[ GitHub ]

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

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

#invalid_only_except_options(valid_actions, only:, except:) (private)

[ GitHub ]

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

def invalid_only_except_options(valid_actions, only:, except:)
  [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 1374

alias :member_name :singular

#member_scope (readonly) Also known as: #shallow_scope

[ GitHub ]

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

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

#name

[ GitHub ]

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

def name
  @as || @name
end

#nested_param

[ GitHub ]

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

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

#nested_scope (readonly)

[ GitHub ]

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

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

#new_scope(new_path)

[ GitHub ]

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

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

#plural

[ GitHub ]

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

def plural
  @plural ||= name.to_s
end

#resource_scope

[ GitHub ]

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

def resource_scope
  controller
end

#shallow_scope

Alias for #member_scope.

[ GitHub ]

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

alias :shallow_scope :member_scope

#singular Also known as: #member_name

[ GitHub ]

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

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