Module: CIMI::Model::Schema::DSL
- Included in:
- Resource, CIMI::Model::Schema
- Defined in:
- lib/cimi/models/schema.rb
Overview
The DSL
Requires that the class into which this is included has a add_attributes!
method
Instance Method Summary collapse
- #array(name, opts = {}, &block) ⇒ Object
- #collection(name, opts = {}) ⇒ Object
- #hash(name) ⇒ Object
- #href(*args) ⇒ Object
- #ref(name, opts = {}) ⇒ Object
- #resource_attr(name, opts = {}) ⇒ Object
- #scalar(*args) ⇒ Object
- #struct(name, opts = {}, &block) ⇒ Object
- #text(*args) ⇒ Object
Instance Method Details
#array(name, opts = {}, &block) ⇒ Object
448 449 450 |
# File 'lib/cimi/models/schema.rb', line 448 def array(name, opts={}, &block) add_attributes!([name, opts], Array, &block) end |
#collection(name, opts = {}) ⇒ Object
468 469 470 471 |
# File 'lib/cimi/models/schema.rb', line 468 def collection(name, opts={}) opts[:scope] = self.class add_attributes!([name, opts], Collection) end |
#hash(name) ⇒ Object
464 465 466 |
# File 'lib/cimi/models/schema.rb', line 464 def hash(name) add_attributes!([name, {}], Hash) end |
#href(*args) ⇒ Object
434 435 436 437 |
# File 'lib/cimi/models/schema.rb', line 434 def href(*args) opts = args.extract_opts! args.each { |arg| struct(arg, opts) { scalar :href, :required => opts[:required] } } end |
#ref(name, opts = {}) ⇒ Object
456 457 458 459 460 461 462 |
# File 'lib/cimi/models/schema.rb', line 456 def ref(name, opts={}) unless opts[:class] s = name.to_s.camelize.gsub(/Config$/, "Configuration") opts[:class] = CIMI::Model::const_get(s) end add_attributes!([name, opts], Ref) end |
#resource_attr(name, opts = {}) ⇒ Object
425 426 427 428 429 430 431 432 |
# File 'lib/cimi/models/schema.rb', line 425 def resource_attr(name, opts={}) CIMI::Model::ResourceMetadata.add_resource_attribute!(self, name, opts) if opts[:type] send(opts[:type], name) else text name end end |
#scalar(*args) ⇒ Object
444 445 446 |
# File 'lib/cimi/models/schema.rb', line 444 def scalar(*args) add_attributes!(args, Scalar) end |
#struct(name, opts = {}, &block) ⇒ Object
452 453 454 |
# File 'lib/cimi/models/schema.rb', line 452 def struct(name, opts={}, &block) add_attributes!([name, opts], Struct, &block) end |
#text(*args) ⇒ Object
439 440 441 442 |
# File 'lib/cimi/models/schema.rb', line 439 def text(*args) args.(:text => :nested) scalar(*args) end |