Class: ActionDispatch::Routing::Mapper::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
actionpack/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.



870
871
872
873
874
875
876
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 870

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



868
869
870
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 868

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options



868
869
870
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 868

def options
  @options
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path



868
869
870
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 868

def path
  @path
end

Instance Method Details

#actionsObject



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

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.



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

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

#default_actionsObject



878
879
880
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 878

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

#member_scopeObject



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

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

#nameObject



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

def name
  @as || @name
end

#nested_scopeObject



926
927
928
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 926

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

#new_scope(new_path) ⇒ Object



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

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

#pluralObject



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

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



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

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



900
901
902
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 900

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