diff --git a/lib/draper/collection_decorator.rb b/lib/draper/collection_decorator.rb index e5d9aae..2710b17 100644 --- a/lib/draper/collection_decorator.rb +++ b/lib/draper/collection_decorator.rb @@ -3,9 +3,11 @@ module Draper include Enumerable include ViewHelpers - attr_accessor :source, :context + attr_reader :source alias_method :to_source, :source + attr_accessor :context + array_methods = Array.instance_methods - Object.instance_methods delegate :as_json, *array_methods, to: :decorated_collection diff --git a/lib/draper/decorator.rb b/lib/draper/decorator.rb index 999a3e3..979b883 100755 --- a/lib/draper/decorator.rb +++ b/lib/draper/decorator.rb @@ -5,11 +5,12 @@ module Draper include Draper::ViewHelpers include ActiveModel::Serialization if defined?(ActiveModel::Serialization) - attr_accessor :source, :context - + attr_reader :source alias_method :model, :source alias_method :to_source, :source + attr_accessor :context + # Initialize a new decorator instance by passing in # an instance of the source class. Pass in an optional # :context inside the options hash which is available @@ -257,8 +258,8 @@ module Draper def handle_multiple_decoration(options) if source.instance_of?(self.class) - self.context = source.context unless options.has_key?(:context) - self.source = source.source + @context = source.context unless options.has_key?(:context) + @source = source.source elsif source.decorated_with?(self.class) warn "Reapplying #{self.class} decorator to target that is already decorated with it. Call stack:\n#{caller(1).join("\n")}" end