Skip to content

Commit

Permalink
Merge pull request #1383 from beauby/simplify-associations
Browse files Browse the repository at this point in the history
Simplify reflections handling.
  • Loading branch information
bf4 committed Dec 22, 2015
2 parents 9909908 + 762f298 commit b6a4ad1
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions lib/active_model/serializer/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,12 @@ class Serializer
# So you can inspect reflections in your Adapters.
#
Reflection = Struct.new(:name, :options, :block) do
delegate :call, to: :reader

attr_reader :reader

def initialize(*)
super
@reader = self.class.build_reader(name, block)
end

# @api private
def value(instance)
call(instance)
end

# @api private
def self.build_reader(name, block)
if block
->(instance) { instance.read_attribute_for_serialization(name).instance_eval(&block) }
instance.read_attribute_for_serialization(name).instance_eval(&block)
else
->(instance) { instance.read_attribute_for_serialization(name) }
instance.read_attribute_for_serialization(name)
end
end

Expand Down

0 comments on commit b6a4ad1

Please sign in to comment.