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
- .catalog_sections ⇒ Object
-
.fullname_for(klass_name) ⇒ Object
Turns a type name into its dotted (avro-style) name, regardless of its current form.
-
.klassname_for(obj) ⇒ Object
Converts a type name to its ruby (camel-cased) form.
- .receive(hsh) ⇒ Object
- .record?(tt) ⇒ Boolean
- .schema_for(obj) ⇒ Object
-
.simple?(tt) ⇒ Boolean
true if class is among the defined primitive types: null boolean integer long float double string binary and so forth.
- .union?(tt) ⇒ Boolean
Methods included from ReceiverModel::ActsAsCatalog
Class Method Details
.catalog_sections ⇒ Object
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.
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.
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 |
.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
160 |
# File 'lib/icss/type.rb', line 160 def self.simple?(tt) ::Icss::SIMPLE_TYPES.has_value?(tt) ; end |