module Cyrax::Extensions::HasResource
Public Instance Methods
resource_attributes()
click to toggle source
# File lib/cyrax/extensions/has_resource.rb, line 34 def resource_attributes filter_attributes(dirty_resource_attributes) end
resource_class()
click to toggle source
Returns the resource class as a constant - e.g. Product
# File lib/cyrax/extensions/has_resource.rb, line 13 def resource_class if self.resource_class_name self.resource_class_name.constantize else resource_name.classify.constantize end end
resource_scope()
click to toggle source
Returns the resource class - e.g. Product If you want your resource to return something interesting, you should override this in your resource by defining the method and returning your own scope
@example Overriding resource_scope
class Products::UserResource < Products::BaseResource def resource_scope accessor.products end end
# File lib/cyrax/extensions/has_resource.rb, line 30 def resource_scope resource_class end
response_name()
click to toggle source
# File lib/cyrax/extensions/has_resource.rb, line 38 def response_name resource_name end
Private Instance Methods
default_resource_attributes()
click to toggle source
# File lib/cyrax/extensions/has_resource.rb, line 82 def default_resource_attributes {} end
dirty_resource_attributes()
click to toggle source
# File lib/cyrax/extensions/has_resource.rb, line 74 def dirty_resource_attributes if Cyrax.strong_parameters params.require(resource_name) else params[resource_name] || {} end end
filter_attributes(attributes)
click to toggle source
# File lib/cyrax/extensions/has_resource.rb, line 86 def filter_attributes(attributes) if Cyrax.strong_parameters attributes.permit(self.class.accessible_attributes) elsif self.class.accessible_attributes.blank? attributes else attributes.slice(*self.class.accessible_attributes) end end