module BTech module Rest module ClassMethods # Allows an object to belong to a parent object, thus creating a nested hierarchy. This behaves in a similar # fashion to the belongs_to ActiveRecord macro. Accepts the following parameters: # * *parent* - The parent symbol (including namespaces delimited by underscores). Be sure to reflect singular or plural forms on the name. 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. The following options are accepted: # * *parent_key* - The ID key of the parent resource (for nested resources only). Defaults to: _id # * *parent_value* - The ID value of the parent resource (for nested resources only). Defaults to the record id. # * *parent_resource_method* - 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. # * *name* - The resource name. Defaults to the controller name. # * *label* - The resource label. Defaults to the controller name with capitalization. # * *controller* - The controller class. Defaults to the current class. You should not need to change this. # * *model* - The model class. Defaults to a model of the same name as the controller (minus namespace, suffix, and pluralization of course). # * *record* - The record (new or found) related to the resource. # * *namespaces* - The namespaces (if any) for routing. Defaults to whatever namespace your controller is using. # * *show_partial* - The show partial. Defaults to "///_show". # * *new_or_edit_partial* - The new or edit partial. 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. Accepts the following parameters: # * *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 end