Sha256: 7a9cc10c3d5c390fcceefed450510a5ce74abeeeaaa9c8bc35b91634c8aaa754

Contents?: true

Size: 589 Bytes

Versions: 22

Compression:

Stored size: 589 Bytes

Contents

require "test_helper"

require "ostruct"
require "pp"


source = OpenStruct.new(name: "30 Years Live", songs: [
  OpenStruct.new(id: 1, title: "Dear Beloved"), OpenStruct.new(id: 2, title: "Fuck Armageddon")])

pp source

require "representable/object"

class AlbumRepresenter < Representable::Decorator
  include Representable::Object

  property :name
  collection :songs, instance: ->(fragment, *) { Song.new } do
    property :title
  end
end


Album = Struct.new(:name, :songs)
Song = Struct.new(:title)

target = Album.new

AlbumRepresenter.new(target).from_object(source)

pp target

Version data entries

22 entries across 18 versions & 1 rubygems

Version Path
representable-3.0.3 test/examples/object.rb
representable-3.0.2 test/examples/object.rb
representable-3.0.1 test/examples/object.rb
representable-3.0.0 test/examples/object.rb
representable-2.4.1 test-with-deprecations/examples/object.rb
representable-2.4.1 test/examples/object.rb
representable-2.4.0 test-with-deprecations/examples/object.rb
representable-2.4.0 test/examples/object.rb
representable-2.4.0.rc5 test/examples/object.rb
representable-2.4.0.rc5 test-with-deprecations/examples/object.rb
representable-2.4.0.rc4 test/examples/object.rb
representable-2.4.0.rc4 test-with-deprecations/examples/object.rb
representable-2.4.0.rc3 test/examples/object.rb
representable-2.4.0.rc2 test/examples/object.rb
representable-2.4.0.rc1 test/examples/object.rb
representable-2.3.0 test/examples/object.rb
representable-2.2.3 test/examples/object.rb
representable-2.2.2 test/examples/object.rb
representable-2.2.1 test/examples/object.rb
representable-2.2.0 test/examples/object.rb