app/models/concerns/blacklight/document.rb in blacklight-6.6.2 vs app/models/concerns/blacklight/document.rb in blacklight-6.7.0

- old
+ new

@@ -12,10 +12,13 @@ # # It also provides support for Document Extensions, which advertise supported # transformation formats. # module Blacklight::Document + extend Deprecation + self.deprecation_horizon = 'blacklight 7.0' + autoload :ActiveModelShim, 'blacklight/document/active_model_shim' autoload :SchemaOrg, 'blacklight/document/schema_org' autoload :CacheKey, 'blacklight/document/cache_key' autoload :DublinCore, 'blacklight/document/dublin_core' autoload :Email, 'blacklight/document/email' @@ -36,10 +39,11 @@ include GlobalID::Identification end attr_reader :response, :_source alias_method :solr_response, :response + delegate :[], :key?, :keys, :to_h, to: :_source def initialize(source_doc={}, response=nil) @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc) @response = response apply_extensions @@ -47,19 +51,24 @@ # the wrapper method to the @_source object. # If a method is missing, it gets sent to @_source # with all of the original params and block def method_missing(m, *args, &b) + return super if m == :to_hash + if _source_responds_to?(m) + Deprecation.warn(Blacklight::Solr::Document, "Blacklight::Document##{m} is deprecated; use obj.to_h.#{m} instead.") _source.send(m, *args, &b) else super end end - def respond_to_missing? *args - _source_responds_to?(*args) || super + def respond_to_missing? m, *args + return super if m == :to_hash + + _source_responds_to?(m, *args) || super end # Helper method to check if value/multi-values exist for a given key. # The value can be a string, or a RegExp # Multiple "values" can be given; only one needs to match. @@ -85,11 +94,9 @@ end end end end alias has_field? has? - - delegate :key?, to: :_source alias has_key? key? def fetch key, *default if key? key self[key]