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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Resource.



867
868
869
870
871
872
873
# File 'lib/action_dispatch/routing/mapper.rb', line 867

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

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



865
866
867
# File 'lib/action_dispatch/routing/mapper.rb', line 865

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



865
866
867
# File 'lib/action_dispatch/routing/mapper.rb', line 865

def options
  @options
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



865
866
867
# File 'lib/action_dispatch/routing/mapper.rb', line 865

def path
  @path
end

Instance Method Details

#actionsObject



879
880
881
882
883
884
885
886
887
# File 'lib/action_dispatch/routing/mapper.rb', line 879

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.



905
906
907
# File 'lib/action_dispatch/routing/mapper.rb', line 905

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

#default_actionsObject



875
876
877
# File 'lib/action_dispatch/routing/mapper.rb', line 875

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

#member_scopeObject



915
916
917
# File 'lib/action_dispatch/routing/mapper.rb', line 915

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

#nameObject



889
890
891
# File 'lib/action_dispatch/routing/mapper.rb', line 889

def name
  @as || @name
end

#nested_scopeObject



923
924
925
# File 'lib/action_dispatch/routing/mapper.rb', line 923

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

#new_scope(new_path) ⇒ Object



919
920
921
# File 'lib/action_dispatch/routing/mapper.rb', line 919

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

#pluralObject



893
894
895
# File 'lib/action_dispatch/routing/mapper.rb', line 893

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



909
910
911
# File 'lib/action_dispatch/routing/mapper.rb', line 909

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



897
898
899
# File 'lib/action_dispatch/routing/mapper.rb', line 897

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