Sha256: fd7d1d0674cdbbf283ec3c380605764629a181fc9bc16190768bacf0dc0f1256

Contents?: true

Size: 626 Bytes

Versions: 1

Compression:

Stored size: 626 Bytes

Contents

module Roar::Rails
  module Responder
    def extend_with_representer!(resource, representer=nil)
      representer ||= representer_for_resource(resource)
      resource.extend(representer)
    end
    def display(resource, given_options={})
      if resource.respond_to?(:map!)
        resource.map! do |r|
          extend_with_representer!(r)
          r.to_hash
        end
      else
        extend_with_representer!(resource, options.delete(:with_representer))
      end
      super
    end
    private
    def representer_for_resource(resource)
      (resource.class.name + "Representer").constantize
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roar-rails-0.0.3 lib/roar/rails/responder.rb