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

Constant Summary collapse

DEFAULT_ACTIONS =
[:index, :create, :new, :show, :update, :destroy, :edit]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities, options = {}) ⇒ Resource

Returns a new instance of Resource.



793
794
795
796
797
798
799
# File 'lib/action_dispatch/routing/mapper.rb', line 793

def initialize(entities, options = {})
  @name       = entities.to_s
  @path       = (options.delete(:path) || @name).to_s
  @controller = (options.delete(:controller) || @name).to_s
  @as         = options.delete(:as)
  @options    = options
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



791
792
793
# File 'lib/action_dispatch/routing/mapper.rb', line 791

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



791
792
793
# File 'lib/action_dispatch/routing/mapper.rb', line 791

def options
  @options
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



791
792
793
# File 'lib/action_dispatch/routing/mapper.rb', line 791

def path
  @path
end

Instance Method Details

#actionsObject



805
806
807
808
809
810
811
812
813
# File 'lib/action_dispatch/routing/mapper.rb', line 805

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 they’re.



830
831
832
# File 'lib/action_dispatch/routing/mapper.rb', line 830

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

#default_actionsObject



801
802
803
# File 'lib/action_dispatch/routing/mapper.rb', line 801

def default_actions
  self.class::DEFAULT_ACTIONS
end

#member_scopeObject



840
841
842
# File 'lib/action_dispatch/routing/mapper.rb', line 840

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

#nameObject



815
816
817
# File 'lib/action_dispatch/routing/mapper.rb', line 815

def name
  @as || @name
end

#nested_scopeObject



848
849
850
# File 'lib/action_dispatch/routing/mapper.rb', line 848

def nested_scope
  "#{path}/:#{singular}_id"
end

#new_scope(new_path) ⇒ Object



844
845
846
# File 'lib/action_dispatch/routing/mapper.rb', line 844

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

#pluralObject



819
820
821
# File 'lib/action_dispatch/routing/mapper.rb', line 819

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



834
835
836
# File 'lib/action_dispatch/routing/mapper.rb', line 834

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



823
824
825
# File 'lib/action_dispatch/routing/mapper.rb', line 823

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