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 they’re.
- #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.
805 806 807 808 809 810 811 |
# File 'lib/action_dispatch/routing/mapper.rb', line 805 def initialize(entities, = {}) @name = entities.to_s @path = (.delete(:path) || @name).to_s @controller = (.delete(:controller) || @name).to_s @as = .delete(:as) @options = end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
803 804 805 |
# File 'lib/action_dispatch/routing/mapper.rb', line 803 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
803 804 805 |
# File 'lib/action_dispatch/routing/mapper.rb', line 803 def @options end |
#path ⇒ Object (readonly) Also known as: collection_scope
Returns the value of attribute path.
803 804 805 |
# File 'lib/action_dispatch/routing/mapper.rb', line 803 def path @path end |
Instance Method Details
#actions ⇒ Object
817 818 819 820 821 822 823 824 825 |
# File 'lib/action_dispatch/routing/mapper.rb', line 817 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 they’re.
842 843 844 |
# File 'lib/action_dispatch/routing/mapper.rb', line 842 def collection_name singular == plural ? "#{plural}_index" : plural end |
#default_actions ⇒ Object
813 814 815 |
# File 'lib/action_dispatch/routing/mapper.rb', line 813 def default_actions self.class::DEFAULT_ACTIONS end |
#member_scope ⇒ Object
852 853 854 |
# File 'lib/action_dispatch/routing/mapper.rb', line 852 def member_scope "#{path}/:id" end |
#name ⇒ Object
827 828 829 |
# File 'lib/action_dispatch/routing/mapper.rb', line 827 def name @as || @name end |
#nested_scope ⇒ Object
860 861 862 |
# File 'lib/action_dispatch/routing/mapper.rb', line 860 def nested_scope "#{path}/:#{singular}_id" end |
#new_scope(new_path) ⇒ Object
856 857 858 |
# File 'lib/action_dispatch/routing/mapper.rb', line 856 def new_scope(new_path) "#{path}/#{new_path}" end |
#plural ⇒ Object
831 832 833 |
# File 'lib/action_dispatch/routing/mapper.rb', line 831 def plural @plural ||= name.to_s end |
#resource_scope ⇒ Object
846 847 848 |
# File 'lib/action_dispatch/routing/mapper.rb', line 846 def resource_scope { :controller => controller } end |
#singular ⇒ Object Also known as: member_name
835 836 837 |
# File 'lib/action_dispatch/routing/mapper.rb', line 835 def singular @singular ||= name.to_s.singularize end |