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

Instance Method Details

#array(name, opts = {}, &block) ⇒ Object



444
445
446
# File 'lib/cimi/models/schema.rb', line 444

def array(name, opts={}, &block)
  add_attributes!([name, opts], Array, &block)
end

#collection(name, opts = {}) ⇒ Object



464
465
466
467
# File 'lib/cimi/models/schema.rb', line 464

def collection(name, opts={})
  opts[:scope] = self
  add_attributes!([name, opts], Collection)
end

#hash_map(name) ⇒ Object



460
461
462
# File 'lib/cimi/models/schema.rb', line 460

def hash_map(name)
  add_attributes!([name, {}], Hash)
end

#href(*args) ⇒ Object



430
431
432
433
# File 'lib/cimi/models/schema.rb', line 430

def href(*args)
  opts = args.extract_opts!
  args.each { |arg| struct(arg, opts) { scalar :href, :required => opts[:required] } }
end

#ref(name, opts = {}) ⇒ Object



452
453
454
455
456
457
458
# File 'lib/cimi/models/schema.rb', line 452

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

#scalar(*args) ⇒ Object



440
441
442
# File 'lib/cimi/models/schema.rb', line 440

def scalar(*args)
  add_attributes!(args, Scalar)
end

#struct(name, opts = {}, &block) ⇒ Object



448
449
450
# File 'lib/cimi/models/schema.rb', line 448

def struct(name, opts={}, &block)
  add_attributes!([name, opts], Struct, &block)
end

#text(*args) ⇒ Object



435
436
437
438
# File 'lib/cimi/models/schema.rb', line 435

def text(*args)
  args.expand_opts!(:text => :nested)
  scalar(*args)
end