Module: Restorm::Model::Paths::ClassMethods
- Defined in:
- lib/restorm/model/paths.rb
Instance Method Summary collapse
-
#collection_path(path = nil) ⇒ Object
Defines a custom collection path for the resource.
-
#primary_key(value = nil) ⇒ Object
Define the primary key field that will be used to find and save records.
-
#resource_path(path = nil) ⇒ Object
Defines a custom resource path for the resource.
Instance Method Details
#collection_path(path = nil) ⇒ Object
Defines a custom collection path for the resource
47 48 49 50 51 52 53 54 |
# File 'lib/restorm/model/paths.rb', line 47 def collection_path(path = nil) if path.nil? @_restorm_collection_path ||= root_element.to_s.pluralize else @_restorm_collection_path = path @_restorm_resource_path = "#{path}/:id" end end |
#primary_key(value = nil) ⇒ Object
Define the primary key field that will be used to find and save records
31 32 33 34 35 36 37 38 |
# File 'lib/restorm/model/paths.rb', line 31 def primary_key(value = nil) @_restorm_primary_key ||= begin superclass.primary_key if superclass.respond_to?(:primary_key) end return @_restorm_primary_key unless value @_restorm_primary_key = value.to_sym end |
#resource_path(path = nil) ⇒ Object
Defines a custom resource path for the resource
Note that, if used in combination with resource_path, you may specify either the real primary key or the string ‘:id’. For example:
79 80 81 82 83 84 85 |
# File 'lib/restorm/model/paths.rb', line 79 def resource_path(path = nil) if path.nil? @_restorm_resource_path ||= "#{root_element.to_s.pluralize}/:id" else @_restorm_resource_path = path end end |