Class: ActionDispatch::Routing::Mapper::Resources::Resource
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper::Resources::Resource
- Defined in:
- 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.
Instance Method Summary collapse
- #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, 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, options = {}) ⇒ Resource
Returns a new instance of Resource.
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1115 def initialize(entities, api_only, shallow, = {}) @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 |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
1113 1114 1115 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1113 def controller @controller end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
1113 1114 1115 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1113 def param @param end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
1113 1114 1115 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1113 def path @path end |
Instance Method Details
#actions ⇒ Object
1136 1137 1138 1139 1140 1141 1142 1143 1144 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1136 def actions if @only Array(@only).map(&:to_sym) elsif @except default_actions - Array(@except).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.
1162 1163 1164 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1162 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
1128 1129 1130 1131 1132 1133 1134 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1128 def default_actions if @api_only [:index, :create, :show, :update, :destroy] else [:index, :create, :new, :show, :update, :destroy, :edit] end end |
#member_scope ⇒ Object Also known as: shallow_scope
1172 1173 1174 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1172 def member_scope "#{path}/:#{param}" end |
#name ⇒ Object
1146 1147 1148 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1146 def name @as || @name end |
#nested_param ⇒ Object
1182 1183 1184 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1182 def nested_param :"#{singular}_#{param}" end |
#nested_scope ⇒ Object
1186 1187 1188 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1186 def nested_scope "#{path}/:#{nested_param}" end |
#new_scope(new_path) ⇒ Object
1178 1179 1180 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1178 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
1150 1151 1152 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1150 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
1166 1167 1168 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1166 def resource_scope controller end |
#shallow? ⇒ Boolean
1190 1191 1192 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1190 def shallow? @shallow end |
#singleton? ⇒ Boolean
1194 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1194 def singleton?; false; end |
#singular ⇒ Object Also known as: member_name
1154 1155 1156 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1154 def singular @singular ||= name.to_s.singularize end |