Module: Daylight::ReflectionExt
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/daylight/reflection_ext.rb
Overview
Extension to use the API namespace and version modules to lookup classes for a reflection. The benefit is to be able to define an association wihtout the module name or using the :class_name option.
Without the extension, we have to specify the ‘:class_name`:
class API::V1::Post < Daylight::API
has_many :comments, class_name: 'api/v1/comment'
end
With the extension, it will be determined using the namespace and version modules
class API::V1::Post < Daylight::API
belongs_to :blog
end
API::V1::Post.find(1).blog #=> #<API::V1::Blog:0x007ffa8a43f1e8 ...>
The ‘:class_name` option still can be specified for alternate behavior
class API::V1::Post < Daylight::API
belongs_to :author, class_name: 'api/v1/user', foreign_key: 'created_by'
end