Module: TwirpRails::ActiveRecordExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/twirp_rails/active_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#to_twirp(*fields_or_class) ⇒ Hash

Converts to twirp hash, used by relation method to_twirp

Parameters:

  • fields_or_class (Array|Class)
    • array of converted fields or message class to

Returns:

  • (Hash)

    of attributes



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twirp_rails/active_record_extension.rb', line 28

def to_twirp(*fields_or_class)
  if fields_or_class.empty? && self.class.twirp_message_class
    to_twirp_as_class(self.class.twirp_message_class)
  elsif fields_or_class.one? && fields_or_class.first.is_a?(Class)
    to_twirp_as_class(fields_or_class.first)
  elsif fields_or_class.any?
    to_twirp_as_fields(fields_or_class)
  else
    attributes
  end
end