Sha256: 928b881d1dd059fbb8ae3ad153a2f394be7913f3dd498691cc9bd8f87c6677a8

Contents?: true

Size: 485 Bytes

Versions: 30

Compression:

Stored size: 485 Bytes

Contents

class RestModel
  class Embeddable
    module Response
      def to_resource(parent)
        return {} unless visible?(parent)

        resource = nil

        if embedded = parent.__send__(name)
          resource = raw? ? embedded : resourcify(embedded)
        elsif many?
          resource = []
        end

        {name => resource}
      end

      private

      def resourcify(embedded)
        one? ? embedded.resource : embedded.map(&:resource)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rest_model-0.3.1 lib/rest_model/key/embeddable/response.rb
rest_model-0.3.0 lib/rest_model/key/embeddable/response.rb
rest_model-0.2.3 lib/rest_model/key/embeddable/response.rb
rest_model-0.2.1 lib/rest_model/key/embeddable/response.rb
rest_model-0.2.0 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.24 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.23 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.22 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.21 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.20 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.19 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.18 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.17 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.16 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.15 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.14 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.13 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.12 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.11 lib/rest_model/key/embeddable/response.rb
rest_model-0.1.10 lib/rest_model/key/embeddable/response.rb