Object
Schemas are generally referenced through an object of this class.
Create a new schema wrapper object given a root field. This is a low-level method. Usually you should call Versionomy::Schema#create instead.
# File lib/versionomy/schema/wrapper.rb, line 75 def initialize(field_, modules_=[], aliases_={}) @root_field = field_ @names = @root_field._descendants_by_name @modules = modules_ @aliases = {} aliases_.each do |k_,v_| k_ = k_.to_sym v_ = v_.to_sym if @names.include?(v_) && !@names.include?(k_) @aliases[k_] = v_ end end end
Returns true if this schema is compatible with the other schema. Two schemas are compatible if their root fields are the same– which means that the entire field tree is the same. They may, however, include different value modules. Note that this is different from the definition of eql?.
# File lib/versionomy/schema/wrapper.rb, line 117 def ==(obj_) eql?(obj_) end
If the RHS is a schema, returns true if the schemas are equivalent. If the RHS is a value, returns true if the value uses this schema.
# File lib/versionomy/schema/wrapper.rb, line 125 def ===(obj_) if obj_.kind_of?(Value) obj_.schema == self else obj_ == self end end
Returns a hash of field name aliases.
# File lib/versionomy/schema/wrapper.rb, line 185 def aliases @aliases.dup end
Return the canonical field name given a name, or nil if the name is not recognized.
# File lib/versionomy/schema/wrapper.rb, line 149 def canonical_name(name_) name_ = name_.to_sym name_ = @aliases[name_] || name_ @names.include?(name_) ? name_ : nil end
Returns true if this schema is equivalent to the other schema. Two schemas are equivalent if their root fields are the same– which means that the entire field tree is the same– and they include the same value modules. Note that this is different from the definition of ==.
# File lib/versionomy/schema/wrapper.rb, line 105 def eql?(obj_) return false unless obj_.kind_of?(Schema::Wrapper) return @root_field == obj_.root_field && @modules == obj_.modules && @aliases == obj_.aliases end
Return the field with the given name, or nil if the given name is not found in this schema. If include_aliases_ is set to true, this also supports lookup by alias.
# File lib/versionomy/schema/wrapper.rb, line 160 def field_named(name_, include_aliases_=false) name_ = name_.to_sym name_ = @aliases[name_] || name_ if include_aliases_ @names[name_] end
Returns an array of modules that should be included in values that use this schema.
# File lib/versionomy/schema/wrapper.rb, line 178 def modules @modules.dup end
Generated with the Darkfish Rdoc Generator 2.