Sha256: f557881abedb8b774d23e1aada3c4d9e4decaaa0904b6f388e5d218b5012b51c

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

class Trailblazer::Operation
  module Representer
    def self.infer(contract_class, format:Representable::JSON)
      Disposable::Rescheme.from(contract_class,
        include:          [format],
        options_from:     :deserializer, # use :instance etc. in deserializer.
        superclass:       Representable::Decorator,
        definitions_from: lambda { |inline| inline.definitions },
        exclude_options:  [:default, :populator], # TODO: test with populator: in an operation.
        exclude_properties: [:persisted?]
      )
    end

    module DSL
      def representer(name=:default, constant=nil, &block)
        heritage.record(:representer, name, constant, &block)

        # FIXME: make this nicer. we want to extend same-named callback groups.
        # TODO: allow the same with contract, or better, test it!
        path, representer_class = Trailblazer::DSL::Build.new.({ prefix: :representer, class: representer_base_class, container: self }, name, constant, block)

        self[path] = representer_class
      end

      # TODO: make engine configurable?
      def representer_base_class
        Class.new(Representable::Decorator) { include Representable::JSON; self }
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
trailblazer-2.0.7 lib/trailblazer/operation/representer.rb
trailblazer-2.0.6 lib/trailblazer/operation/representer.rb
trailblazer-2.0.5 lib/trailblazer/operation/representer.rb
trailblazer-2.0.4 lib/trailblazer/operation/representer.rb
trailblazer-2.0.3 lib/trailblazer/operation/representer.rb
trailblazer-2.0.2 lib/trailblazer/operation/representer.rb
trailblazer-2.0.1 lib/trailblazer/operation/representer.rb
trailblazer-2.0.0 lib/trailblazer/operation/representer.rb
trailblazer-2.0.0.rc1 lib/trailblazer/operation/representer.rb
trailblazer-2.0.0.beta3 lib/trailblazer/operation/representer.rb
trailblazer-2.0.0.beta2 lib/trailblazer/operation/representer.rb
trailblazer-2.0.0.beta1 lib/trailblazer/operation/representer.rb