mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Make source read-only
This commit is contained in:
parent
a70bc5d098
commit
24839274c5
2 changed files with 8 additions and 5 deletions
|
@ -3,9 +3,11 @@ module Draper
|
||||||
include Enumerable
|
include Enumerable
|
||||||
include ViewHelpers
|
include ViewHelpers
|
||||||
|
|
||||||
attr_accessor :source, :context
|
attr_reader :source
|
||||||
alias_method :to_source, :source
|
alias_method :to_source, :source
|
||||||
|
|
||||||
|
attr_accessor :context
|
||||||
|
|
||||||
array_methods = Array.instance_methods - Object.instance_methods
|
array_methods = Array.instance_methods - Object.instance_methods
|
||||||
delegate :as_json, *array_methods, to: :decorated_collection
|
delegate :as_json, *array_methods, to: :decorated_collection
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,12 @@ module Draper
|
||||||
include Draper::ViewHelpers
|
include Draper::ViewHelpers
|
||||||
include ActiveModel::Serialization if defined?(ActiveModel::Serialization)
|
include ActiveModel::Serialization if defined?(ActiveModel::Serialization)
|
||||||
|
|
||||||
attr_accessor :source, :context
|
attr_reader :source
|
||||||
|
|
||||||
alias_method :model, :source
|
alias_method :model, :source
|
||||||
alias_method :to_source, :source
|
alias_method :to_source, :source
|
||||||
|
|
||||||
|
attr_accessor :context
|
||||||
|
|
||||||
# Initialize a new decorator instance by passing in
|
# Initialize a new decorator instance by passing in
|
||||||
# an instance of the source class. Pass in an optional
|
# an instance of the source class. Pass in an optional
|
||||||
# :context inside the options hash which is available
|
# :context inside the options hash which is available
|
||||||
|
@ -257,8 +258,8 @@ module Draper
|
||||||
|
|
||||||
def handle_multiple_decoration(options)
|
def handle_multiple_decoration(options)
|
||||||
if source.instance_of?(self.class)
|
if source.instance_of?(self.class)
|
||||||
self.context = source.context unless options.has_key?(:context)
|
@context = source.context unless options.has_key?(:context)
|
||||||
self.source = source.source
|
@source = source.source
|
||||||
elsif source.decorated_with?(self.class)
|
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")}"
|
warn "Reapplying #{self.class} decorator to target that is already decorated with it. Call stack:\n#{caller(1).join("\n")}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue