app/models/concerns/blacklight/document.rb in blacklight-6.21.0 vs app/models/concerns/blacklight/document.rb in blacklight-6.22.0
- old
+ new
@@ -142,9 +142,25 @@
module ClassMethods
attr_writer :unique_key
def unique_key
@unique_key ||= 'id'
end
+
+ # Define an attribute reader on a document model
+ # @Example
+ # class SolrDocument
+ # include Blacklight::Solr::Document
+ # attribute :title, Blacklight::Types::String, 'title_tesim'
+ # end
+ #
+ # doc = SolrDocument.new(title_tesim: ["One flew over the cuckoo's nest"])
+ # doc.title
+ # #=> "One flew over the cuckoo's nest"
+ def attribute(name, type, field)
+ define_method name do
+ type.coerce(self[field])
+ end
+ end
end
private
def _source_responds_to? *args