Class: CIMI::Model::Schema::Ref
- Defined in:
- lib/cimi/models/schema.rb
Instance Attribute Summary
Attributes inherited from Struct
Attributes inherited from Attribute
#json_name, #name, #required, #xml_name
Instance Method Summary collapse
-
#initialize(name, opts = {}, &block) ⇒ Ref
constructor
A new instance of Ref.
-
#valid?(value) ⇒ Boolean
The ‘ref’ could be the reference to a CIMI entity or the full CIMI entity representation.
Methods inherited from Struct
#convert, #convert_from_json, #convert_from_xml, #convert_to_json, #convert_to_xml, #from_json, #from_xml, #to_json, #to_xml
Methods inherited from Attribute
#convert, #from_json, #from_xml, #required?, #to_json, #to_xml
Constructor Details
#initialize(name, opts = {}, &block) ⇒ Ref
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/cimi/models/schema.rb', line 194 def initialize(name, opts={}, &block) raise 'The :class attribute must be set' unless opts[:class] refname = "#{opts[:class].name.split("::").last}Ref" if CIMI::Model::const_defined?(refname) @klass = CIMI::Model::const_get(refname) else @klass = Class.new(opts[:class]) do |m| scalar :href end CIMI::Model::const_set(refname, @klass) end @klass.class_eval { def href?; !href.nil?; end } opts[:schema] = @klass.schema super(name, opts, &block) end |
Instance Method Details
#valid?(value) ⇒ Boolean
The ‘ref’ could be the reference to a CIMI entity or the full CIMI entity representation.
213 214 215 216 217 |
# File 'lib/cimi/models/schema.rb', line 213 def valid?(value) !value.href.nil? || @klass.schema.required_attributes.all? { |a| a.valid?(value.send(a.name)) } end |