Class: Icss::RecordType
- Defined in:
- lib/icss/type.rb,
lib/icss/type/factory.rb
Overview
Icss/Avro Record type
Records use the type name “record” and support these attributes:
-
name: a string providing the name of the record (required).
-
namespace: a string that qualifies the name;
-
doc: a string providing documentation to the user of this schema (optional).
-
fields: an array of RecordField’s (required).
For example, a linked-list of 64-bit values may be defined with:
{
"type": "record",
"name": "LongList",
"fields" : [
{"name": "value", "type": "long"}, // each element has a long
{"name": "next", "type": ["LongList", "null"]} // optional next element
]
}
Direct Known Subclasses
Constant Summary
Constants inherited from Type
Instance Attribute Summary
Attributes inherited from NamedType
Instance Method Summary collapse
- #decorate_with_conveniences(klass) ⇒ Object
- #decorate_with_receivers(klass) ⇒ Object
- #define_klass ⇒ Object
- #ensure_parent_modules! ⇒ Object
- #ruby_klass ⇒ Object
- #ruby_klass_name ⇒ Object
- #ruby_klass_parent ⇒ Object
- #ruby_klass_scope_names ⇒ Object
- #to_hash ⇒ Object
Methods inherited from NamedType
#fullname, #name=, #namespace, #receive_namespace
Methods included from Validations
#validate_name, #validate_namespace
Methods inherited from Type
find, pig_name, primitive?, #primitive?, #title, #to_json
Instance Method Details
#decorate_with_conveniences(klass) ⇒ Object
168 169 170 |
# File 'lib/icss/type/factory.rb', line 168 def decorate_with_conveniences klass klass.send :include, Receiver::ActsAsHash end |
#decorate_with_receivers(klass) ⇒ Object
162 163 164 165 166 |
# File 'lib/icss/type/factory.rb', line 162 def decorate_with_receivers klass fields.each do |field| field.define_receiver_on(klass) end end |
#define_klass ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/icss/type/factory.rb', line 145 def define_klass ensure_parent_modules! parent_module = ruby_klass_parent klass_basename = ruby_klass_scope_names.last.to_sym klass = parent_module.const_get(klass_basename) rescue nil klass ||= parent_module.const_set(klass_basename, Class.new(::Icss::MetaType)) klass end |
#ensure_parent_modules! ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/icss/type/factory.rb', line 136 def ensure_parent_modules! ruby_klass_scope_names[0..-2].inject(Object) do |parent_module, module_name| new_parent = "::#{parent_module}::#{module_name}".constantize rescue nil new_parent ||= parent_module.const_set(module_name.to_sym, Module.new) # p [parent_module, new_parent, module_name] new_parent end end |
#ruby_klass ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/icss/type/factory.rb', line 154 def ruby_klass return @klass if @klass klass = define_klass decorate_with_receivers(klass) decorate_with_conveniences(klass) @klass = klass end |
#ruby_klass_name ⇒ Object
129 130 131 |
# File 'lib/icss/type/factory.rb', line 129 def ruby_klass_name "::" + ruby_klass_scope_names.join('::') end |
#ruby_klass_parent ⇒ Object
132 133 134 |
# File 'lib/icss/type/factory.rb', line 132 def ruby_klass_parent ("::" + ruby_klass_scope_names[0..-2].join('::')).constantize end |
#ruby_klass_scope_names ⇒ Object
126 127 128 |
# File 'lib/icss/type/factory.rb', line 126 def ruby_klass_scope_names fullname.split('.').map(&:camelize) end |
#to_hash ⇒ Object
345 346 347 |
# File 'lib/icss/type.rb', line 345 def to_hash super.merge( :fields => (fields||[]).map{|field| field.to_hash} ) end |