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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#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, 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=(value) ⇒ Object
- #shallow? ⇒ Boolean
- #singular ⇒ Object (also: #member_name)
Constructor Details
#initialize(entities, options = {}) ⇒ Resource
Returns a new instance of Resource.
1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1062 def initialize(entities, = {}) @name = entities.to_s @path = ([:path] || @name).to_s @controller = ([:controller] || @name).to_s @as = [:as] @param = ([:param] || :id).to_sym @options = @shallow = false end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
1060 1061 1062 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1060 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
1060 1061 1062 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1060 def @options end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
1060 1061 1062 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1060 def param @param end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
1060 1061 1062 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1060 def path @path end |
Instance Method Details
#actions ⇒ Object
1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1076 def actions if only = @options[:only] Array(only).map(&:to_sym) elsif except = @options[: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.
1102 1103 1104 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1102 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
1072 1073 1074 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1072 def default_actions [:index, :create, :new, :show, :update, :destroy, :edit] end |
#member_scope ⇒ Object Also known as: shallow_scope
1112 1113 1114 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1112 def member_scope "#{path}/:#{param}" end |
#name ⇒ Object
1086 1087 1088 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1086 def name @as || @name end |
#nested_param ⇒ Object
1122 1123 1124 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1122 def nested_param :"#{singular}_#{param}" end |
#nested_scope ⇒ Object
1126 1127 1128 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1126 def nested_scope "#{path}/:#{nested_param}" end |
#new_scope(new_path) ⇒ Object
1118 1119 1120 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1118 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
1090 1091 1092 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1090 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
1106 1107 1108 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1106 def resource_scope { :controller => controller } end |
#shallow=(value) ⇒ Object
1130 1131 1132 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1130 def shallow=(value) @shallow = value end |
#shallow? ⇒ Boolean
1134 1135 1136 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1134 def shallow? @shallow end |
#singular ⇒ Object Also known as: member_name
1094 1095 1096 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1094 def singular @singular ||= name.to_s.singularize end |