Class: ActionDispatch::Routing::Mapper::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/action_dispatch/routing/mapper.rb

Overview

:nodoc:

Direct Known Subclasses

SingletonResource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities, api_only, shallow, options = {}) ⇒ Resource

Returns a new instance of Resource.



1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/action_dispatch/routing/mapper.rb', line 1126

def initialize(entities, api_only, shallow, options = {})
  @name       = entities.to_s
  @path       = (options[:path] || @name).to_s
  @controller = (options[:controller] || @name).to_s
  @as         = options[:as]
  @param      = (options[:param] || :id).to_sym
  @options    = options
  @shallow    = shallow
  @api_only   = api_only
  @only       = options.delete :only
  @except     = options.delete :except
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



1124
1125
1126
# File 'lib/action_dispatch/routing/mapper.rb', line 1124

def controller
  @controller
end

#paramObject (readonly)

Returns the value of attribute param.



1124
1125
1126
# File 'lib/action_dispatch/routing/mapper.rb', line 1124

def param
  @param
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



1124
1125
1126
# File 'lib/action_dispatch/routing/mapper.rb', line 1124

def path
  @path
end

Instance Method Details

#actionsObject



1147
1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/action_dispatch/routing/mapper.rb', line 1147

def actions
  if @only
    Array(@only).map(&:to_sym)
  elsif @except
    default_actions - Array(@except).map(&:to_sym)
  else
    default_actions
  end
end

#collection_nameObject

Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.



1173
1174
1175
# File 'lib/action_dispatch/routing/mapper.rb', line 1173

def collection_name
  singular == plural ? "#{plural}_index" : plural
end

#default_actionsObject



1139
1140
1141
1142
1143
1144
1145
# File 'lib/action_dispatch/routing/mapper.rb', line 1139

def default_actions
  if @api_only
    [:index, :create, :show, :update, :destroy]
  else
    [:index, :create, :new, :show, :update, :destroy, :edit]
  end
end

#member_scopeObject Also known as: shallow_scope



1183
1184
1185
# File 'lib/action_dispatch/routing/mapper.rb', line 1183

def member_scope
  "#{path}/:#{param}"
end

#nameObject



1157
1158
1159
# File 'lib/action_dispatch/routing/mapper.rb', line 1157

def name
  @as || @name
end

#nested_paramObject



1193
1194
1195
# File 'lib/action_dispatch/routing/mapper.rb', line 1193

def nested_param
  :"#{singular}_#{param}"
end

#nested_scopeObject



1197
1198
1199
# File 'lib/action_dispatch/routing/mapper.rb', line 1197

def nested_scope
  "#{path}/:#{nested_param}"
end

#new_scope(new_path) ⇒ Object



1189
1190
1191
# File 'lib/action_dispatch/routing/mapper.rb', line 1189

def new_scope(new_path)
  "#{path}/#{new_path}"
end

#pluralObject



1161
1162
1163
# File 'lib/action_dispatch/routing/mapper.rb', line 1161

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



1177
1178
1179
# File 'lib/action_dispatch/routing/mapper.rb', line 1177

def resource_scope
  controller
end

#shallow?Boolean

Returns:

  • (Boolean)


1201
1202
1203
# File 'lib/action_dispatch/routing/mapper.rb', line 1201

def shallow?
  @shallow
end

#singleton?Boolean

Returns:

  • (Boolean)


1205
# File 'lib/action_dispatch/routing/mapper.rb', line 1205

def singleton?; false; end

#singularObject Also known as: member_name



1165
1166
1167
# File 'lib/action_dispatch/routing/mapper.rb', line 1165

def singular
  @singular ||= name.to_s.singularize
end