module Rest module ClassMethods # Describes the parent/child relationship of a resource. The behavior is similar to the belongs_to macro in ActiveRecord. # * *parent* - The parent symbol (including namespaces delimited by underscores). Example: Public::PostsController, Result: :public_posts def belongs_to parent @parent_resource = parent.to_s class_eval "class << self; attr_accessor :parent_resource end" end # Allows one to specify the various options for a resource. # * *parent_key* - Optional. The ID key of the parent resource (for nested resources only). Defaults to: _id # * *parent_value* - Optional. The ID value of the parent resource (for nested resources only). Defaults to the record id. # * *parent_resource_method* - Optional. The instance method to call for acquiring child resource(s) of the parent (for nested resources only). Example: A post with many comments would be post.comments. Defaults to child resource name. # * *controller_class* - Optional. The controller class (for nested resources only). Defaults to the current class. You should never need to use this. # * *controller_name* - Optional. The controller name. Defaults to the controller class name minus the "Controller" suffix (same behavior as used in routing). Example: PostsController => posts # * *label* - Optional. The resource label. Defaults to the controller name with capitalization. Example: posts => Posts. # * *model_class* - Optional. The model class. Defaults to the same name as the controller (minus namespace, suffix, and pluralization of course). Example: PostsController => Post # * *model_name* - Optional. The model name. Defaults to the singularized version of the :controller_name. Example: posts (controller_name) => post (model_name). # * *model_object* - Optional. The model object. The name defaults to the model_name. Example: post (model_name) => @post (model object). You should never need to use this. # * *namespaces* - Optional. The namespaces (if any) for routing. Defaults to whatever namespace your controller is using. # * *index_template* - Optional. The index template. Defaults to "///index". # * *show_template* - Optional. The show template. Defaults to "///show". # * *new_or_edit_template* - Optional. The new or edit template. Defaults to "///new_or_edit". def resource_options options = {} @resource_options = options class_eval "class << self; attr_reader :resource_options end" end # Allows one to disable any number of default actions. # * *actions* - A variable list of REST action symbols you wish to disable. You may use any of the following: index, show, new, create, edit, update, and/or destroy. def disabled_actions *actions actions.uniq.each {|action| undef_method action} end end end