Class: Protobuf::ActiveRecord::Transformer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Transformer.



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

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

Instance Attribute Details

#callableObject

Returns the value of attribute callable.



4
5
6
# File 'lib/protobuf/active_record/transformer.rb', line 4

def callable
  @callable
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/protobuf/active_record/transformer.rb', line 4

def options
  @options
end

Instance Method Details

#nullify?(proto) ⇒ Boolean

Returns:

  • (Boolean)


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

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