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

Inherits:
Object
  • Object
show all
Defined in:
actionpack/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.



963
964
965
966
967
968
969
970
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 963

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
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller



961
962
963
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 961

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options



961
962
963
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 961

def options
  @options
end

#paramObject (readonly)

Returns the value of attribute param



961
962
963
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 961

def param
  @param
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path



961
962
963
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 961

def path
  @path
end

Instance Method Details

#actionsObject



976
977
978
979
980
981
982
983
984
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 976

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.



1002
1003
1004
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1002

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

#default_actionsObject



972
973
974
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 972

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

#member_scopeObject Also known as: shallow_scope



1012
1013
1014
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1012

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

#nameObject



986
987
988
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 986

def name
  @as || @name
end

#nested_paramObject



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

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

#nested_scopeObject



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

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

#new_scope(new_path) ⇒ Object



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

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

#pluralObject



990
991
992
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 990

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



1006
1007
1008
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 1006

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



994
995
996
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 994

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