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.



994
995
996
997
998
999
1000
1001
1002
# File 'lib/action_dispatch/routing/mapper.rb', line 994

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.



992
993
994
# File 'lib/action_dispatch/routing/mapper.rb', line 992

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



992
993
994
# File 'lib/action_dispatch/routing/mapper.rb', line 992

def options
  @options
end

#paramObject (readonly)

Returns the value of attribute param.



992
993
994
# File 'lib/action_dispatch/routing/mapper.rb', line 992

def param
  @param
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



992
993
994
# File 'lib/action_dispatch/routing/mapper.rb', line 992

def path
  @path
end

Instance Method Details

#actionsObject



1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/action_dispatch/routing/mapper.rb', line 1008

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.



1034
1035
1036
# File 'lib/action_dispatch/routing/mapper.rb', line 1034

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

#default_actionsObject



1004
1005
1006
# File 'lib/action_dispatch/routing/mapper.rb', line 1004

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

#member_scopeObject Also known as: shallow_scope



1044
1045
1046
# File 'lib/action_dispatch/routing/mapper.rb', line 1044

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

#nameObject



1018
1019
1020
# File 'lib/action_dispatch/routing/mapper.rb', line 1018

def name
  @as || @name
end

#nested_paramObject



1054
1055
1056
# File 'lib/action_dispatch/routing/mapper.rb', line 1054

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

#nested_scopeObject



1058
1059
1060
# File 'lib/action_dispatch/routing/mapper.rb', line 1058

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

#new_scope(new_path) ⇒ Object



1050
1051
1052
# File 'lib/action_dispatch/routing/mapper.rb', line 1050

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

#pluralObject



1022
1023
1024
# File 'lib/action_dispatch/routing/mapper.rb', line 1022

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



1038
1039
1040
# File 'lib/action_dispatch/routing/mapper.rb', line 1038

def resource_scope
  { :controller => controller }
end

#shallow=(value) ⇒ Object



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

def shallow=(value)
  @shallow = value
end

#shallow?Boolean

Returns:

  • (Boolean)


1066
1067
1068
# File 'lib/action_dispatch/routing/mapper.rb', line 1066

def shallow?
  @shallow
end

#singularObject Also known as: member_name



1026
1027
1028
# File 'lib/action_dispatch/routing/mapper.rb', line 1026

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