Module: Icss::Meta::NamedType
- Included in:
- RecordType
- Defined in:
- lib/icss/type/named_type.rb
Overview
Record, Error, Enum and Fixed are named types. Each has a fullname that is composed of two parts; a name and a namespace. Equality of names is defined on the fullname.
The name portion of a fullname, and record field names, must:
-
start with [A-Za-z_]
-
subsequently contain only [A-Za-z0-9_]
-
A namespace is a dot-separated sequence of such names.
References to previously defined names are as in the latter two cases above: if they contain a dot they are a fullname, if they do not contain a dot, the namespace is the namespace of the enclosing definition.
Simple type names have no namespace and their names may not be defined in any namespace. A schema may only contain multiple definitions of a fullname if the definitions are equivalent.
Class Method Summary collapse
-
.make(fullname, superklass) ⇒ Object
Manufactures klass and metamodel.
Instance Method Summary collapse
- #basename ⇒ Object
- #doc ⇒ Object
- #doc=(str) ⇒ Object
- #fullname ⇒ Object
- #is_core? ⇒ Boolean
-
#metamodel ⇒ Object
Returns the metamodel – a module extending the type, on which all the accessors and receive methods are inscribed.
- #namespace ⇒ Object
- #pathname ⇒ Object
- #to_schema ⇒ Object
Class Method Details
.make(fullname, superklass) ⇒ Object
Manufactures klass and metamodel
for type science.astronomy.ufo_sighting, we synthesize
-
a module, ::Icss::Meta::Science::Astronomy::UfoSightingType
-
a class, ::Icss::Science::Astronomy::UfoSighting
If no superklass is given, Icss::Entity is used.
83 84 85 86 87 88 89 |
# File 'lib/icss/type/named_type.rb', line 83 def self.make(fullname, superklass) klass = get_model_klass(fullname, superklass) = (klass.to_s) klass.class_eval{ extend(::Icss::Meta::NamedType) } klass.class_eval{ include() } [klass, ] end |
Instance Method Details
#basename ⇒ Object
35 36 37 |
# File 'lib/icss/type/named_type.rb', line 35 def basename @basename ||= fullname.to_s.gsub(/.*[\.]/, "") end |
#doc ⇒ Object
24 |
# File 'lib/icss/type/named_type.rb', line 24 def doc() "" end |
#doc=(str) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/icss/type/named_type.rb', line 25 def doc=(str) singleton_class.class_eval do remove_possible_method(:doc) define_method(:doc){ str } end end |
#fullname ⇒ Object
32 33 34 |
# File 'lib/icss/type/named_type.rb', line 32 def fullname ::Icss::Meta::Type.fullname_for(self.name) end |
#is_core? ⇒ Boolean
54 55 56 |
# File 'lib/icss/type/named_type.rb', line 54 def is_core? respond_to?(:_schema) && _schema.is_core? end |
#metamodel ⇒ Object
Returns the metamodel – a module extending the type, on which all the accessors and receive methods are inscribed. (This allows you to call super() from within receive_foo)
68 69 70 71 72 73 |
# File 'lib/icss/type/named_type.rb', line 68 def return @metamodel if @metamodel @metamodel = Icss::Meta::NamedType.(self.to_s) self.class_eval{ include(@metamodel) } @metamodel end |
#namespace ⇒ Object
38 39 40 |
# File 'lib/icss/type/named_type.rb', line 38 def namespace @namespace ||= fullname.to_s.include?('.') ? fullname.to_s.gsub(/\.[^\.]+\z/so, '') : '' end |
#pathname ⇒ Object
41 42 43 |
# File 'lib/icss/type/named_type.rb', line 41 def pathname fullname.to_s.gsub(/\./, '/') end |
#to_schema ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/icss/type/named_type.rb', line 45 def to_schema if respond_to?(:_schema) then return _schema.to_hash ; end { :name => fullname, # :namespace => namespace, :doc => doc, }.compact_blank end |