Class: ActionController::Resources::Resource
- Defined in:
- lib/action_controller/resources.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_ACTIONS =
:index, :create, :new, :edit, :show, :update, :destroy
Instance Attribute Summary collapse
-
#collection_methods ⇒ Object
readonly
Returns the value of attribute collection_methods.
-
#member_methods ⇒ Object
readonly
Returns the value of attribute member_methods.
-
#name_prefix ⇒ Object
readonly
Returns the value of attribute name_prefix.
-
#new_methods ⇒ Object
readonly
Returns the value of attribute new_methods.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path_prefix ⇒ Object
readonly
Returns the value of attribute path_prefix.
-
#path_segment ⇒ Object
readonly
Returns the value of attribute path_segment.
-
#plural ⇒ Object
readonly
Returns the value of attribute plural.
-
#singular ⇒ Object
readonly
Returns the value of attribute singular.
Instance Method Summary collapse
- #action_separator ⇒ Object
- #conditions ⇒ Object
- #controller ⇒ Object
- #has_action?(action) ⇒ Boolean
-
#initialize(entities, options) ⇒ Resource
constructor
A new instance of Resource.
- #member_path ⇒ Object
- #nesting_name_prefix ⇒ Object
- #nesting_path_prefix ⇒ Object
- #new_path ⇒ Object
- #path ⇒ Object
- #requirements(with_id = false) ⇒ Object
- #shallow_name_prefix ⇒ Object
- #shallow_path_prefix ⇒ Object
- #uncountable? ⇒ Boolean
Constructor Details
#initialize(entities, options) ⇒ Resource
Returns a new instance of Resource.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/action_controller/resources.rb', line 55 def initialize(entities, ) @plural ||= entities @singular ||= [:singular] || plural.to_s.singularize @path_segment = .delete(:as) || @plural @options = arrange_actions add_default_actions set_allowed_actions set_prefixes end |
Instance Attribute Details
#collection_methods ⇒ Object (readonly)
Returns the value of attribute collection_methods.
50 51 52 |
# File 'lib/action_controller/resources.rb', line 50 def collection_methods @collection_methods end |
#member_methods ⇒ Object (readonly)
Returns the value of attribute member_methods.
50 51 52 |
# File 'lib/action_controller/resources.rb', line 50 def member_methods @member_methods end |
#name_prefix ⇒ Object (readonly)
Returns the value of attribute name_prefix.
51 52 53 |
# File 'lib/action_controller/resources.rb', line 51 def name_prefix @name_prefix end |
#new_methods ⇒ Object (readonly)
Returns the value of attribute new_methods.
50 51 52 |
# File 'lib/action_controller/resources.rb', line 50 def new_methods @new_methods end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
53 54 55 |
# File 'lib/action_controller/resources.rb', line 53 def @options end |
#path_prefix ⇒ Object (readonly)
Returns the value of attribute path_prefix.
51 52 53 |
# File 'lib/action_controller/resources.rb', line 51 def path_prefix @path_prefix end |
#path_segment ⇒ Object (readonly)
Returns the value of attribute path_segment.
51 52 53 |
# File 'lib/action_controller/resources.rb', line 51 def path_segment @path_segment end |
#plural ⇒ Object (readonly)
Returns the value of attribute plural.
52 53 54 |
# File 'lib/action_controller/resources.rb', line 52 def plural @plural end |
#singular ⇒ Object (readonly)
Returns the value of attribute singular.
52 53 54 |
# File 'lib/action_controller/resources.rb', line 52 def singular @singular end |
Instance Method Details
#action_separator ⇒ Object
113 114 115 |
# File 'lib/action_controller/resources.rb', line 113 def action_separator @action_separator ||= Base.resource_action_separator end |
#conditions ⇒ Object
79 80 81 |
# File 'lib/action_controller/resources.rb', line 79 def conditions @conditions ||= @options[:conditions] || {} end |
#controller ⇒ Object
68 69 70 |
# File 'lib/action_controller/resources.rb', line 68 def controller @controller ||= "#{[:namespace]}#{([:controller] || plural).to_s}" end |
#has_action?(action) ⇒ Boolean
121 122 123 |
# File 'lib/action_controller/resources.rb', line 121 def has_action?(action) !DEFAULT_ACTIONS.include?(action) || action_allowed?(action) end |
#member_path ⇒ Object
97 98 99 |
# File 'lib/action_controller/resources.rb', line 97 def member_path @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id" end |
#nesting_name_prefix ⇒ Object
109 110 111 |
# File 'lib/action_controller/resources.rb', line 109 def nesting_name_prefix "#{shallow_name_prefix}#{singular}_" end |
#nesting_path_prefix ⇒ Object
101 102 103 |
# File 'lib/action_controller/resources.rb', line 101 def nesting_path_prefix @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id" end |
#new_path ⇒ Object
87 88 89 90 91 |
# File 'lib/action_controller/resources.rb', line 87 def new_path new_action = self.[:path_names][:new] if self.[:path_names] new_action ||= Base.resources_path_names[:new] @new_path ||= "#{path}/#{new_action}" end |
#path ⇒ Object
83 84 85 |
# File 'lib/action_controller/resources.rb', line 83 def path @path ||= "#{path_prefix}/#{path_segment}" end |
#requirements(with_id = false) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/action_controller/resources.rb', line 72 def requirements(with_id = false) @requirements ||= @options[:requirements] || {} @id_requirement ||= { :id => @requirements.delete(:id) || /[^#{Routing::SEPARATORS.join}]+/ } with_id ? @requirements.merge(@id_requirement) : @requirements end |
#shallow_name_prefix ⇒ Object
105 106 107 |
# File 'lib/action_controller/resources.rb', line 105 def shallow_name_prefix @shallow_name_prefix ||= @options[:shallow] ? @options[:namespace].try(:gsub, /\//, '_') : name_prefix end |
#shallow_path_prefix ⇒ Object
93 94 95 |
# File 'lib/action_controller/resources.rb', line 93 def shallow_path_prefix @shallow_path_prefix ||= @options[:shallow] ? @options[:namespace].try(:sub, /\/$/, '') : path_prefix end |
#uncountable? ⇒ Boolean
117 118 119 |
# File 'lib/action_controller/resources.rb', line 117 def uncountable? @singular.to_s == @plural.to_s end |