lib/express_templates/components/capabilities/resourceful.rb in express_templates-0.11.4 vs lib/express_templates/components/capabilities/resourceful.rb in express_templates-0.11.5

- old
+ new

@@ -4,11 +4,11 @@ module Resourceful def self.included(base) base.class_eval do - has_argument :id, "The name of the collection", type: :symbol, optional: false + has_argument :id, "The name of the collection. A resourceful component will look for the resource based on the ID.", type: :symbol, optional: false has_option :collection, 'Provide an explicit collection as a resource.' has_option :collection_path, 'Provide an explicit path for the collection resource.', type: [:string, :proc] has_option :resource_class, 'Overrides namespaced resource_class for using resources from a different module or namespace.' has_option :resource_path, 'Overides the resource path which is otherwise inferred from the class name.', type: [:string, :proc] has_option :path_prefix, 'Rarely used. Override inferred path_prefix for path helpers.' @@ -27,11 +27,19 @@ config[:path_prefix] || infer_path_prefix end def resource_class resource_class = config[:resource_class] || _namespaced_resource_class - resource_class.constantize + if Object.const_defined?(resource_class) + resource_class.constantize + else + message = [ + "Could not find the class `#{resource_class}`.", + "You may need to define the option `:resource_class`.", + ].join(" ") + fail ArgumentError, message + end end private def _namespaced_resource_class @@ -204,10 +212,14 @@ def resource_attributes resource_class.columns end def resource - self.send(resource_name) + begin + self.send(resource_name) + rescue NoMethodError + nil + end end end end end end