Class: ActiveRemote::Serializers::Protobuf::Fields

Inherits:
Object
  • Object
show all
Defined in:
lib/active_remote/serializers/protobuf.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_class, attributes = {}) ⇒ Fields

Constructor!



44
45
46
47
# File 'lib/active_remote/serializers/protobuf.rb', line 44

def initialize(message_class, attributes = {})
  @attributes = attributes
  @message_class = message_class
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



39
40
41
# File 'lib/active_remote/serializers/protobuf.rb', line 39

def attributes
  @attributes
end

#message_classObject (readonly)

Returns the value of attribute message_class.



39
40
41
# File 'lib/active_remote/serializers/protobuf.rb', line 39

def message_class
  @message_class
end

Class Method Details

.from_attributes(message_class, attributes) ⇒ Object

Class methods



52
53
54
55
# File 'lib/active_remote/serializers/protobuf.rb', line 52

def self.from_attributes(message_class, attributes)
  fields = new(message_class, attributes)
  fields.from_attributes
end

Instance Method Details

#from_attributesObject

Instance methods



60
61
62
63
64
65
66
67
# File 'lib/active_remote/serializers/protobuf.rb', line 60

def from_attributes
  attributes.each_with_object({}) do |(key, value), hash|
    field = message_class.get_field(key, true) # Check extension fields, too
    value = Field.from_attribute(field, value) if field

    hash[key] = value
  end
end