Class: ActionController::Resources::Resource

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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/action_controller/resources.rb', line 51

def initialize(entities, options)
  @plural   ||= entities
  @singular ||= options[:singular] || plural.to_s.singularize
  @path_segment = options.delete(:as) || @plural

  @options = options

  arrange_actions
  add_default_actions
  set_prefixes
end

Instance Attribute Details

#collection_methodsObject (readonly)

Returns the value of attribute collection_methods.



46
47
48
# File 'lib/action_controller/resources.rb', line 46

def collection_methods
  @collection_methods
end

#member_methodsObject (readonly)

Returns the value of attribute member_methods.



46
47
48
# File 'lib/action_controller/resources.rb', line 46

def member_methods
  @member_methods
end

#name_prefixObject (readonly)

Returns the value of attribute name_prefix.



47
48
49
# File 'lib/action_controller/resources.rb', line 47

def name_prefix
  @name_prefix
end

#new_methodsObject (readonly)

Returns the value of attribute new_methods.



46
47
48
# File 'lib/action_controller/resources.rb', line 46

def new_methods
  @new_methods
end

#optionsObject (readonly)

Returns the value of attribute options.



49
50
51
# File 'lib/action_controller/resources.rb', line 49

def options
  @options
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



47
48
49
# File 'lib/action_controller/resources.rb', line 47

def path_prefix
  @path_prefix
end

#path_segmentObject (readonly)

Returns the value of attribute path_segment.



47
48
49
# File 'lib/action_controller/resources.rb', line 47

def path_segment
  @path_segment
end

#pluralObject (readonly)

Returns the value of attribute plural.



48
49
50
# File 'lib/action_controller/resources.rb', line 48

def plural
  @plural
end

#singularObject (readonly)

Returns the value of attribute singular.



48
49
50
# File 'lib/action_controller/resources.rb', line 48

def singular
  @singular
end

Instance Method Details

#action_separatorObject



100
101
102
# File 'lib/action_controller/resources.rb', line 100

def action_separator
  @action_separator ||= Base.resource_action_separator
end

#conditionsObject



74
75
76
# File 'lib/action_controller/resources.rb', line 74

def conditions
  @conditions = @options[:conditions] || {}
end

#controllerObject



63
64
65
# File 'lib/action_controller/resources.rb', line 63

def controller
  @controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}"
end

#member_pathObject



88
89
90
# File 'lib/action_controller/resources.rb', line 88

def member_path
  @member_path ||= "#{path}/:id"
end

#nesting_name_prefixObject



96
97
98
# File 'lib/action_controller/resources.rb', line 96

def nesting_name_prefix
  "#{name_prefix}#{singular}_"
end

#nesting_path_prefixObject



92
93
94
# File 'lib/action_controller/resources.rb', line 92

def nesting_path_prefix
  @nesting_path_prefix ||= "#{path}/:#{singular}_id"
end

#new_pathObject



82
83
84
85
86
# File 'lib/action_controller/resources.rb', line 82

def new_path
  new_action = self.options[:path_names][:new] if self.options[:path_names]
  new_action ||= Base.resources_path_names[:new]
  @new_path ||= "#{path}/#{new_action}"
end

#pathObject



78
79
80
# File 'lib/action_controller/resources.rb', line 78

def path
  @path ||= "#{path_prefix}/#{path_segment}"
end

#requirements(with_id = false) ⇒ Object



67
68
69
70
71
72
# File 'lib/action_controller/resources.rb', line 67

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

#uncountable?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/action_controller/resources.rb', line 104

def uncountable?
  @singular.to_s == @plural.to_s
end