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
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#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 (also: #shallow_scope)
- #name ⇒ Object
- #nested_param ⇒ 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.
977 978 979 980 981 982 983 984 |
# File 'lib/action_dispatch/routing/mapper.rb', line 977 def initialize(entities, = {}) @name = entities.to_s @path = ([:path] || @name).to_s @controller = ([:controller] || @name).to_s @as = [:as] @param = ([:param] || :id).to_sym @options = end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
975 976 977 |
# File 'lib/action_dispatch/routing/mapper.rb', line 975 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
975 976 977 |
# File 'lib/action_dispatch/routing/mapper.rb', line 975 def @options end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
975 976 977 |
# File 'lib/action_dispatch/routing/mapper.rb', line 975 def param @param end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
975 976 977 |
# File 'lib/action_dispatch/routing/mapper.rb', line 975 def path @path end |
Instance Method Details
#actions ⇒ Object
990 991 992 993 994 995 996 997 998 |
# File 'lib/action_dispatch/routing/mapper.rb', line 990 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.
1016 1017 1018 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1016 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
986 987 988 |
# File 'lib/action_dispatch/routing/mapper.rb', line 986 def default_actions [:index, :create, :new, :show, :update, :destroy, :edit] end |
#member_scope ⇒ Object Also known as: shallow_scope
1026 1027 1028 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1026 def member_scope "#{path}/:#{param}" end |
#name ⇒ Object
1000 1001 1002 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1000 def name @as || @name end |
#nested_param ⇒ Object
1036 1037 1038 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1036 def nested_param :"#{singular}_#{param}" end |
#nested_scope ⇒ Object
1040 1041 1042 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1040 def nested_scope "#{path}/:#{nested_param}" end |
#new_scope(new_path) ⇒ Object
1032 1033 1034 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1032 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
1004 1005 1006 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1004 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
1020 1021 1022 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1020 def resource_scope { :controller => controller } end |
#singular ⇒ Object Also known as: member_name
1008 1009 1010 |
# File 'lib/action_dispatch/routing/mapper.rb', line 1008 def singular @singular ||= name.to_s.singularize end |