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.



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

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.



880
881
882
# File 'lib/action_dispatch/routing/mapper.rb', line 880

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



880
881
882
# File 'lib/action_dispatch/routing/mapper.rb', line 880

def options
  @options
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



880
881
882
# File 'lib/action_dispatch/routing/mapper.rb', line 880

def path
  @path
end

Instance Method Details

#actionsObject



894
895
896
897
898
899
900
901
902
# File 'lib/action_dispatch/routing/mapper.rb', line 894

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.



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

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

#default_actionsObject



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

def default_actions
  self.class::DEFAULT_ACTIONS
end

#member_scopeObject



930
931
932
# File 'lib/action_dispatch/routing/mapper.rb', line 930

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

#nameObject



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

def name
  @as || @name
end

#nested_scopeObject



938
939
940
# File 'lib/action_dispatch/routing/mapper.rb', line 938

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

#new_scope(new_path) ⇒ Object



934
935
936
# File 'lib/action_dispatch/routing/mapper.rb', line 934

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

#pluralObject



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

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



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

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



912
913
914
# File 'lib/action_dispatch/routing/mapper.rb', line 912

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