Module: Cyrax::Extensions::HasResource::ClassMethods

Defined in:
lib/cyrax/extensions/has_resource.rb

Instance Method Summary collapse

Instance Method Details

#accessible_attributes(*attrs) ⇒ Object

Class method for setting all the attributes that you want to access in the resource

Examples:

accessible_attributes :description, :model, :price_in_cents, :vendor

Parameters:

  • attrs (Array(Symbol))

    Symbols of the attributes



37
38
39
40
41
42
43
44
# File 'lib/cyrax/extensions/has_resource.rb', line 37

def accessible_attributes(*attrs)
  if attrs.blank?
    @accessible_attributes || []
  else
    @accessible_attributes ||= []
    @accessible_attributes += attrs
  end
end

#resource(name, options = {}) ⇒ Object

Class method for setting the resource that you want to access

Examples:

resource :product

Parameters:

  • name (Symbol)

    The name of the resource

  • options (defaults to: {})

    Hash [Hash] Options



53
54
55
56
57
58
59
60
61
# File 'lib/cyrax/extensions/has_resource.rb', line 53

def resource(name, options = {})
  if options[:class_name].present?
    ActiveSupport::Deprecation.warn "sending :class_name in #resource method is deprecated. send :class instead"
    options[:class] = options[:class_name].to_s.constantize
  end
  self._resource_name = name.to_s
  self._resource_class = options[:class]
  self._collection_name = name.to_s.pluralize
end