Make source read-only

This commit is contained in:
Andrew Haines 2012-12-19 21:48:37 +00:00
parent a70bc5d098
commit 24839274c5
2 changed files with 8 additions and 5 deletions

View File

@ -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

View File

@ -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