Module: Trailblazer::V1_1::Operation::Representer::DSL

Defined in:
lib/trailblazer/1.1/operation/representer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object


14
15
16
# File 'lib/trailblazer/1.1/operation/representer.rb', line 14

def self.extended(extender)
  extender.inheritable_attr :_representer_class
end

Instance Method Details

#infer_representer_classObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/trailblazer/1.1/operation/representer.rb', line 34

def infer_representer_class
  if Disposable::VERSION =~ /^0.1/
    warn "[Trailblazer] Reform 2.0 won't be supported in Trailblazer 1.2. Don't be lazy and upgrade to Reform 2.1."

    Disposable::Twin::Schema.from(contract_class,
      include:          [Representable::JSON],
      options_from:     :deserializer, # use :instance etc. in deserializer.
      superclass:       Representable::Decorator,
      representer_from: lambda { |inline| inline.representer_class },
    )
  else
    Disposable::Rescheme.from(contract_class,
      include:          [Representable::JSON],
      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
end

#representer(constant = nil, &block) ⇒ Object


18
19
20
21
22
23
# File 'lib/trailblazer/1.1/operation/representer.rb', line 18

def representer(constant=nil, &block)
  return representer_class unless constant or block_given?

  self.representer_class= Class.new(constant) if constant
  representer_class.class_eval(&block) if block_given?
end

#representer_classObject


25
26
27
# File 'lib/trailblazer/1.1/operation/representer.rb', line 25

def representer_class
  self._representer_class ||= infer_representer_class
end

#representer_class=(constant) ⇒ Object


29
30
31
# File 'lib/trailblazer/1.1/operation/representer.rb', line 29

def representer_class=(constant)
  self._representer_class = constant
end