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
-
#collection_scope
readonly
Alias for #path.
- #controller readonly
- #param readonly
- #path (also: #collection_scope, #member_scope, #nested_scope) readonly
- #shallow? ⇒ Boolean readonly
- #singleton? ⇒ Boolean readonly
Instance Method Summary
- #actions
- #available_actions
-
#collection_name
Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.
- #default_actions
-
#member_name
Alias for #singular.
- #member_scope (also: #shallow_scope) readonly
- #name
- #nested_param
- #nested_scope readonly
- #new_scope(new_path)
- #plural
- #resource_scope
-
#shallow_scope
Alias for #member_scope.
- #singular (also: #member_name)
- #invalid_only_except_options(options, valid_actions) private
Constructor Details
.new(entities, api_only, shallow, options = {}) ⇒ Resource
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1177
def initialize(entities, api_only, shallow, = {}) if [: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 = (, valid_actions).presence raise ArgumentError, ":only and :except must include only #{valid_actions}, but also included #{invalid_actions}" end @name = entities.to_s @path = ( [:path] || @name).to_s @controller = ( [:controller] || @name).to_s @as = [:as] @param = ( [:param] || :id).to_sym @options = @shallow = shallow @api_only = api_only @only = .delete :only @except = .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.
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1243
alias :collection_scope :path
#controller (readonly)
[ GitHub ]#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.
#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 (, valid_actions) .values_at(:only, :except).flatten.compact.uniq.map(&:to_sym) - valid_actions end
#member_name
Alias for #singular.
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1231
alias :member_name :singular
#member_scope (readonly) Also known as: #shallow_scope
[ GitHub ]#name
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1219
def name @as || @name end
#nested_param
[ GitHub ]#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.
# 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