Class: Protobuf::Mongoid::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/mongoid/transformer.rb

Overview

Transformer class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callable, options = {}) ⇒ Transformer

Returns a new instance of Transformer.



9
10
11
12
# File 'lib/protobuf/mongoid/transformer.rb', line 9

def initialize(callable, options = {})
  @callable = callable
  @options = options
end

Instance Attribute Details

#callableObject

Returns the value of attribute callable.



7
8
9
# File 'lib/protobuf/mongoid/transformer.rb', line 7

def callable
  @callable
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/protobuf/mongoid/transformer.rb', line 7

def options
  @options
end

Instance Method Details

#call(proto) ⇒ Object



14
15
16
17
18
# File 'lib/protobuf/mongoid/transformer.rb', line 14

def call(proto)
  return unless proto

  callable.call(proto)
end

#nullify?(proto) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/protobuf/mongoid/transformer.rb', line 20

def nullify?(proto)
  return false unless options[:nullify_on]
  return false unless proto.field?(:nullify) && proto.nullify.is_a?(Array)
  return false if proto.nullify.empty?

  proto.nullify.include?(options[:nullify_on].to_s)
end