Module: Protobuf::Mongoid::Serialization::ClassMethods
- Defined in:
- lib/protobuf/mongoid/serialization.rb
Overview
Defined Under Namespace
Classes: CollectionAssociationCaller, DateCaller, DateTimeCaller, FieldSymbolTransformerCaller, NilMethodCaller, NoConversionCaller
Instance Method Summary
collapse
Instance Method Details
#_protobuf_collection_association_object(field) ⇒ Object
103
104
105
|
# File 'lib/protobuf/mongoid/serialization.rb', line 103
def _protobuf_collection_association_object(field)
CollectionAssociationCaller.new(field)
end
|
#_protobuf_convert_to_fields_object(field) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/protobuf/mongoid/serialization.rb', line 147
def _protobuf_convert_to_fields_object(field)
is_datetime_time_or_timestamp_field = _protobuf_date_datetime_time_or_timestamp_field?(field)
is_date_field = _protobuf_date_field?(field)
if is_datetime_time_or_timestamp_field
if is_date_field
DateCaller.new(field)
else
DateTimeCaller.new(field)
end
else
NoConversionCaller.new(field)
end
end
|
#_protobuf_field_objects ⇒ Object
25
26
27
|
# File 'lib/protobuf/mongoid/serialization.rb', line 25
def _protobuf_field_objects
@_protobuf_field_objects ||= {}
end
|
#_protobuf_field_options ⇒ Object
29
30
31
|
# File 'lib/protobuf/mongoid/serialization.rb', line 29
def _protobuf_field_options
@_protobuf_field_options ||= {}
end
|
33
34
35
|
# File 'lib/protobuf/mongoid/serialization.rb', line 33
def _protobuf_field_symbol_transformers
@_protobuf_field_symbol_transformers ||= {}
end
|
162
163
164
|
# File 'lib/protobuf/mongoid/serialization.rb', line 162
def _protobuf_field_transformer_object(field)
_protobuf_field_transformers[field]
end
|
37
38
39
|
# File 'lib/protobuf/mongoid/serialization.rb', line 37
def _protobuf_field_transformers
@_protobuf_field_transformers ||= {}
end
|
#_protobuf_message_deprecated_fields ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/protobuf/mongoid/serialization.rb', line 41
def _protobuf_message_deprecated_fields
@_protobuf_message_deprecated_fields ||=
protobuf_message.all_fields.map do |field|
next if field.nil?
next unless field.deprecated?
field.name.to_sym
end
end
|
#_protobuf_message_non_deprecated_fields ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/protobuf/mongoid/serialization.rb', line 51
def _protobuf_message_non_deprecated_fields
@_protobuf_message_non_deprecated_fields ||=
protobuf_message.all_fields.map do |field|
next if field.nil?
next if field.deprecated?
field.name.to_sym
end
end
|
#_protobuf_nil_object(_field) ⇒ Object
174
175
176
|
# File 'lib/protobuf/mongoid/serialization.rb', line 174
def _protobuf_nil_object(_field)
NilMethodCaller.new
end
|
189
190
191
|
# File 'lib/protobuf/mongoid/serialization.rb', line 189
def _protobuf_symbol_transformer_object(field)
FieldSymbolTransformerCaller.new(self, _protobuf_field_symbol_transformers[field])
end
|
#field_from_document(field, transformer = nil, &block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/protobuf/mongoid/serialization.rb', line 61
def field_from_document(field, transformer = nil, &block)
if transformer.is_a?(Symbol)
_protobuf_field_symbol_transformers[field] = transformer
return
end
transformer ||= block
callable = transformer
raise FieldTransformerError unless callable.respond_to?(:call)
_protobuf_field_transformers[field.to_sym] = callable
end
|
#protobuf_fields(*fields) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/protobuf/mongoid/serialization.rb', line 75
def protobuf_fields(*fields)
options = fields.
options[:only] = fields if fields.present?
self._protobuf_field_options = options
end
|
#protobuf_message(message = nil, options = {}) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/protobuf/mongoid/serialization.rb', line 82
def protobuf_message(message = nil, options = {})
unless message.nil?
@protobuf_message = message.to_s.classify.constantize
self._protobuf_field_options = options
end
@protobuf_message
end
|