Class: MR::ReadModel::JsonStructField
- Inherits:
-
Struct
- Object
- Struct
- MR::ReadModel::JsonStructField
- Defined in:
- lib/mr/read_model/fields.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#read_model_class ⇒ Object
Returns the value of attribute read_model_class.
-
#struct_class_name ⇒ Object
Returns the value of attribute struct_class_name.
Instance Method Summary collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
162 163 164 |
# File 'lib/mr/read_model/fields.rb', line 162 def name @name end |
#read_model_class ⇒ Object
Returns the value of attribute read_model_class
162 163 164 |
# File 'lib/mr/read_model/fields.rb', line 162 def read_model_class @read_model_class end |
#struct_class_name ⇒ Object
Returns the value of attribute struct_class_name
162 163 164 |
# File 'lib/mr/read_model/fields.rb', line 162 def struct_class_name @struct_class_name end |
Instance Method Details
#reader(read_model_data) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/mr/read_model/fields.rb', line 174 def reader(read_model_data) json_value = read_model_data[self.name] return json_value if json_value.nil? if json_value.kind_of?(String) begin return MR::JsonField.decode(json_value) rescue MR::JsonField::InvalidJSONError => exception = "can't decode `#{self.name}` JSON: #{exception.}" raise exception.class, , exception.backtrace end else return json_value end end |
#struct_class ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/mr/read_model/fields.rb', line 164 def struct_class @struct_class ||= if self.struct_class_name.kind_of?(String) names = self.struct_class_name.to_s.split('::').reject{ |name| name.empty? } namespace = self.struct_class_name =~ /^::/ ? Object : self.read_model_class names.inject(namespace){ |o, name| o.const_get(name) } else self.struct_class_name end end |