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.
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, 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.
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File '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 |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
1175 1176 1177 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1175 def controller @controller end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
1175 1176 1177 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1175 def param @param end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
1175 1176 1177 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1175 def path @path end |
Class Method Details
.default_actions(api_only) ⇒ Object
1166 1167 1168 1169 1170 1171 1172 |
# File '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 Method Details
#actions ⇒ Object
1203 1204 1205 1206 1207 1208 1209 |
# File '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 ⇒ Object
1211 1212 1213 1214 1215 1216 1217 |
# File '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 ⇒ Object
Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.
1235 1236 1237 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1235 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
1199 1200 1201 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1199 def default_actions self.class.default_actions(@api_only) end |
#member_scope ⇒ Object Also known as: shallow_scope
1245 1246 1247 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1245 def member_scope "#{path}/:#{param}" end |
#name ⇒ Object
1219 1220 1221 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1219 def name @as || @name end |
#nested_param ⇒ Object
1255 1256 1257 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1255 def nested_param :"#{singular}_#{param}" end |
#nested_scope ⇒ Object
1259 1260 1261 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1259 def nested_scope "#{path}/:#{nested_param}" end |
#new_scope(new_path) ⇒ Object
1251 1252 1253 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1251 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
1223 1224 1225 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1223 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
1239 1240 1241 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1239 def resource_scope controller end |
#shallow? ⇒ Boolean
1263 1264 1265 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1263 def shallow? @shallow end |
#singleton? ⇒ Boolean
1267 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1267 def singleton?; false; end |
#singular ⇒ Object Also known as: member_name
1227 1228 1229 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1227 def singular @singular ||= name.to_s.singularize end |