Class: ActionDispatch::Routing::Mapper::Resources::Resource
- Defined in:
- actionpack/lib/action_dispatch/routing/mapper.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#path ⇒ Object
(also: #collection_scope)
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
- #available_actions ⇒ Object
-
#collection_name ⇒ Object
Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.
- #default_actions ⇒ Object
-
#initialize(entities, api_only, shallow, only: nil, except: nil, **options) ⇒ Resource
constructor
A new instance of Resource.
- #member_scope ⇒ Object (also: #shallow_scope)
- #name ⇒ Object
- #nested_param ⇒ Object
- #nested_scope ⇒ Object
- #new_scope(new_path) ⇒ Object
- #plural ⇒ Object
- #resource_scope ⇒ Object
- #shallow? ⇒ Boolean
- #singleton? ⇒ Boolean
- #singular ⇒ Object (also: #member_name)
Constructor Details
#initialize(entities, api_only, shallow, only: nil, except: nil, **options) ⇒ Resource
Returns a new instance of Resource.
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1319 def initialize(entities, api_only, shallow, only: nil, except: nil, **) 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, 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 = ([:path] || @name).to_s @controller = ([:controller] || @name).to_s @as = [:as] @param = ([:param] || :id).to_sym @options = @shallow = shallow @api_only = api_only @only = only @except = except end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
1317 1318 1319 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1317 def controller @controller end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
1317 1318 1319 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1317 def param @param end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
1317 1318 1319 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1317 def path @path end |
Class Method Details
.default_actions(api_only) ⇒ Object
1308 1309 1310 1311 1312 1313 1314 |
# 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 Method Details
#actions ⇒ Object
1346 1347 1348 1349 1350 1351 1352 |
# 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 ⇒ Object
1354 1355 1356 1357 1358 1359 1360 |
# 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 ⇒ Object
Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.
1378 1379 1380 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1378 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
1342 1343 1344 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1342 def default_actions self.class.default_actions(@api_only) end |
#member_scope ⇒ Object Also known as: shallow_scope
1388 1389 1390 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1388 def member_scope "#{path}/:#{param}" end |
#name ⇒ Object
1362 1363 1364 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1362 def name @as || @name end |
#nested_param ⇒ Object
1398 1399 1400 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1398 def nested_param :"#{singular}_#{param}" end |
#nested_scope ⇒ Object
1402 1403 1404 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1402 def nested_scope "#{path}/:#{nested_param}" end |
#new_scope(new_path) ⇒ Object
1394 1395 1396 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1394 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
1366 1367 1368 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1366 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
1382 1383 1384 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1382 def resource_scope controller end |
#shallow? ⇒ Boolean
1406 1407 1408 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1406 def shallow? @shallow end |
#singleton? ⇒ Boolean
1410 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1410 def singleton?; false; end |
#singular ⇒ Object Also known as: member_name
1370 1371 1372 |
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1370 def singular @singular ||= name.to_s.singularize end |