Sha256: cd20b0d8c59d1849f464337c39fca45f013a0bd25461261f50a4a3e35eff72a5
Contents?: true
Size: 1.44 KB
Versions: 3
Compression:
Stored size: 1.44 KB
Contents
module MakeRestful::ClassMethods def resource_name resource_class.name.gsub(/(.*::)?(.*)/,"\\2").underscore.pluralize end def instance_name resource_name.singularize end private def json_collection_root_node(true_or_name=true) self.json_root_node = if true_or_name === true resource_name elsif true_or_name.is_a?(Symbol) || true_or_name.is_a?(String) true_or_name end end def paginates!(options={}) options.assert_valid_keys(:root_node) self.pagination_options = options end def resource(klass) self.resource_class = klass.to_s.classify.constantize end def collection(options={}, &block) options.assert_valid_keys(:for) key = options[:for].try(:to_sym) || :default self.collection_loader[key] = block if block_given? end def instance(options={}, &block) options.assert_valid_keys(:for) key = options[:for].try(:to_sym) || :default self.instance_loader[key] = block if block_given? end def actions(*actions) options = actions.extract_options! self.allowed_actions.objects = actions if actions.present? self.allowed_actions.only(options[:only]) self.allowed_actions.except(options[:except]) end def formats(*formats) options = formats.extract_options! self.allowed_formats.objects = formats if formats.present? self.allowed_formats.only(options[:only]) self.allowed_formats.except(options[:except]) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
make_restful-0.1.13 | lib/make_restful/class_methods.rb |
make_restful-0.1.11 | lib/make_restful/class_methods.rb |
make_restful-0.1.10 | lib/make_restful/class_methods.rb |