Module: Icss::Meta::Type

Includes:
ReceiverModel::ActsAsCatalog
Defined in:
lib/icss/type.rb,
lib/icss/type.rb

Constant Summary collapse

NORMAL_NAMED_CONSTANT_RE =

:nodoc:

/\A[\w\:\.]+\z/

Class Method Summary collapse

Methods included from ReceiverModel::ActsAsCatalog

included, #register

Class Method Details

.catalog_sectionsObject



5
6
7
# File 'lib/icss/type.rb', line 5

def self.catalog_sections
  ::Icss::Meta::Protocol.catalog_sections
end

.fullname_for(klass_name) ⇒ Object

Turns a type name into its dotted (avro-style) name, regardless of its current form.

Examples:

Icss::Meta::Type.fullname_for(Icss::This::That::TheOther)   # 'this.that.the_other'
Icss::Meta::Type.fullname_for("Icss::This::That::TheOther") # 'this.that.the_other'
Icss::Meta::Type.fullname_for('this.that.the_other')        # 'this.that.the_other'


125
126
127
128
# File 'lib/icss/type.rb', line 125

def self.fullname_for(klass_name)
  return nil unless klass_name.present? && (klass_name.to_s =~ NORMAL_NAMED_CONSTANT_RE)
  klass_name.to_s.gsub(/^:*Icss::/, '').underscore.gsub(%r{/},".")
end

.klassname_for(obj) ⇒ Object

Converts a type name to its ruby (camel-cased) form. Works on class, name of class, or dotted (avro-style) namespace.name. Names will have an ‘Icss::’ prefix.

Examples:

Icss::Meta::Type.fullname_for('this.that.the_other')        # "Icss::This::That::TheOther"
Icss::Meta::Type.fullname_for(Icss::This::That::TheOther)   # "Icss::This::That::TheOther"
Icss::Meta::Type.fullname_for("Icss::This::That::TheOther") # "Icss::This::That::TheOther"


139
140
141
142
143
144
145
# File 'lib/icss/type.rb', line 139

def self.klassname_for(obj)
  return nil unless obj.present? && (obj.to_s =~ NORMAL_NAMED_CONSTANT_RE)
  nm = obj.to_s.gsub(/^:*Icss:+/, '').
    gsub(%r{::},'.').
    split('.').map(&:camelize).join('::')
  "::Icss::#{nm}"
end

.receive(hsh) ⇒ Object



8
9
10
# File 'lib/icss/type.rb', line 8

def self.receive(hsh)
  ::Icss::Meta::Protocol.receive(hsh)
end

.record?(tt) ⇒ Boolean

Returns:



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

def self.record?(tt)    false     ; end

.schema_for(obj) ⇒ Object



147
148
149
150
151
152
# File 'lib/icss/type.rb', line 147

def self.schema_for(obj)
  case
  when obj.respond_to?(:to_schema) then obj.to_schema
  when str = fullname_for(obj)     then str.to_sym
  else nil ; end
end

.simple?(tt) ⇒ Boolean

true if class is among the defined primitive types:

null boolean integer long float double string binary

and so forth

note this takes no account of inheritance – only the types specifically listed in Icss::SIMPLE_TYPES are simple

Returns:



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

def self.simple?(tt)    ::Icss::SIMPLE_TYPES.has_value?(tt)    ; end

.union?(tt) ⇒ Boolean

Returns:



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

def self.union?(tt)     false     ; end