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
Constant Summary collapse
- DEFAULT_ACTIONS =
[:index, :create, :new, :show, :update, :destroy, :edit]
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#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
- #name ⇒ Object
- #nested_scope ⇒ Object
- #new_scope(new_path) ⇒ Object
- #plural ⇒ Object
- #resource_scope ⇒ Object
- #singular ⇒ Object (also: #member_name)
Constructor Details
#initialize(entities, options = {}) ⇒ Resource
Returns a new instance of Resource.
878 879 880 881 882 883 884 |
# File 'lib/action_dispatch/routing/mapper.rb', line 878 def initialize(entities, = {}) @name = entities.to_s @path = ([:path] || @name).to_s @controller = ([:controller] || @name).to_s @as = [:as] @options = end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
876 877 878 |
# File 'lib/action_dispatch/routing/mapper.rb', line 876 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
876 877 878 |
# File 'lib/action_dispatch/routing/mapper.rb', line 876 def @options end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
876 877 878 |
# File 'lib/action_dispatch/routing/mapper.rb', line 876 def path @path end |
Instance Method Details
#actions ⇒ Object
890 891 892 893 894 895 896 897 898 |
# File 'lib/action_dispatch/routing/mapper.rb', line 890 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.
916 917 918 |
# File 'lib/action_dispatch/routing/mapper.rb', line 916 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
886 887 888 |
# File 'lib/action_dispatch/routing/mapper.rb', line 886 def default_actions self.class::DEFAULT_ACTIONS end |
#member_scope ⇒ Object
926 927 928 |
# File 'lib/action_dispatch/routing/mapper.rb', line 926 def member_scope "#{path}/:id" end |
#name ⇒ Object
900 901 902 |
# File 'lib/action_dispatch/routing/mapper.rb', line 900 def name @as || @name end |
#nested_scope ⇒ Object
934 935 936 |
# File 'lib/action_dispatch/routing/mapper.rb', line 934 def nested_scope "#{path}/:#{singular}_id" end |
#new_scope(new_path) ⇒ Object
930 931 932 |
# File 'lib/action_dispatch/routing/mapper.rb', line 930 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
904 905 906 |
# File 'lib/action_dispatch/routing/mapper.rb', line 904 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
920 921 922 |
# File 'lib/action_dispatch/routing/mapper.rb', line 920 def resource_scope { :controller => controller } end |
#singular ⇒ Object Also known as: member_name
908 909 910 |
# File 'lib/action_dispatch/routing/mapper.rb', line 908 def singular @singular ||= name.to_s.singularize end |