Class: Icss::Type

Inherits:
Object
  • Object
show all
Includes:
Receiver
Defined in:
lib/icss/type.rb

Overview

Describes an avro type

A Schema is represented in JSON by one of:

  • A JSON string, naming a defined type.

  • A JSON object, of the form:

    {"type": "typeName" ...attributes...}
    

    where typeName is either a primitive or derived type name, as defined in the Icss::Type class

  • A JSON array, representing a union of embedded types.

Direct Known Subclasses

EnumerableType, NamedType, PrimitiveType

Constant Summary collapse

PRIMITIVE_TYPES =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(type_name) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/icss/type.rb', line 35

def self.find type_name
  if type_name.to_s.include?('.')
    warn "crap. can't properly do namespaced types yet."
    type_name = type_name.to_s.gsub(/(.*)\./, "")
  end
  Icss::Type::VALID_TYPES[type_name.to_sym] || Icss::Type::DERIVED_TYPES[type_name.to_sym]
end

.pig_nameObject

Schema Translation



57
58
59
# File 'lib/icss/type.rb', line 57

def self.pig_name
  "undefined_#{self.to_s.underscore}"
end

.primitive?(name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/icss/type.rb', line 43

def self.primitive? name
  PRIMITIVE_TYPES.include?(name.to_sym)
end

Instance Method Details

#primitive?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/icss/type.rb', line 46

def primitive?
  false
end

#titleObject



50
51
52
# File 'lib/icss/type.rb', line 50

def title
  self.name
end

#to_hashObject

Conversion



64
65
66
# File 'lib/icss/type.rb', line 64

def to_hash()
  {:name => name, :doc => doc }.reject{|k,v| v.nil? }
end

#to_jsonObject

This will cause funny errors when it is an element of something that’s to_json’ed



68
# File 'lib/icss/type.rb', line 68

def to_json() to_hash.to_json ; end