Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make source read-only

  • Loading branch information...
commit 24839274c566145cc4cc0ca192847f849443efb6 1 parent a70bc5d
@haines haines authored
Showing with 8 additions and 5 deletions.
  1. +3 −1 lib/draper/collection_decorator.rb
  2. +5 −4 lib/draper/decorator.rb
View
4 lib/draper/collection_decorator.rb
@@ -3,9 +3,11 @@ class CollectionDecorator
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
9 lib/draper/decorator.rb
@@ -5,11 +5,12 @@ class Decorator
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 @@ def allow?(method)
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
Please sign in to comment.
Something went wrong with that request. Please try again.