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, options = {}) ⇒ Resource

Returns a new instance of Resource.



1063
1064
1065
1066
1067
1068
1069
1070
1071
# File 'lib/action_dispatch/routing/mapper.rb', line 1063

def initialize(entities, 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    = false
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



1061
1062
1063
# File 'lib/action_dispatch/routing/mapper.rb', line 1061

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



1061
1062
1063
# File 'lib/action_dispatch/routing/mapper.rb', line 1061

def options
  @options
end

#paramObject (readonly)

Returns the value of attribute param.



1061
1062
1063
# File 'lib/action_dispatch/routing/mapper.rb', line 1061

def param
  @param
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



1061
1062
1063
# File 'lib/action_dispatch/routing/mapper.rb', line 1061

def path
  @path
end

Instance Method Details

#actionsObject



1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'lib/action_dispatch/routing/mapper.rb', line 1077

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_nameObject

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



1103
1104
1105
# File 'lib/action_dispatch/routing/mapper.rb', line 1103

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

#default_actionsObject



1073
1074
1075
# File 'lib/action_dispatch/routing/mapper.rb', line 1073

def default_actions
  [:index, :create, :new, :show, :update, :destroy, :edit]
end

#member_scopeObject Also known as: shallow_scope



1113
1114
1115
# File 'lib/action_dispatch/routing/mapper.rb', line 1113

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

#nameObject



1087
1088
1089
# File 'lib/action_dispatch/routing/mapper.rb', line 1087

def name
  @as || @name
end

#nested_paramObject



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

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

#nested_scopeObject



1127
1128
1129
# File 'lib/action_dispatch/routing/mapper.rb', line 1127

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

#new_scope(new_path) ⇒ Object



1119
1120
1121
# File 'lib/action_dispatch/routing/mapper.rb', line 1119

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

#pluralObject



1091
1092
1093
# File 'lib/action_dispatch/routing/mapper.rb', line 1091

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



1107
1108
1109
# File 'lib/action_dispatch/routing/mapper.rb', line 1107

def resource_scope
  { :controller => controller }
end

#shallow=(value) ⇒ Object



1131
1132
1133
# File 'lib/action_dispatch/routing/mapper.rb', line 1131

def shallow=(value)
  @shallow = value
end

#shallow?Boolean

Returns:

  • (Boolean)


1135
1136
1137
# File 'lib/action_dispatch/routing/mapper.rb', line 1135

def shallow?
  @shallow
end

#singularObject Also known as: member_name



1095
1096
1097
# File 'lib/action_dispatch/routing/mapper.rb', line 1095

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