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



370
371
372
# File 'lib/cimi/models/schema.rb', line 370

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

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



382
383
384
385
# File 'lib/cimi/models/schema.rb', line 382

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

#hash(name) ⇒ Object



378
379
380
# File 'lib/cimi/models/schema.rb', line 378

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

#href(*args) ⇒ Object



356
357
358
359
# File 'lib/cimi/models/schema.rb', line 356

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

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



347
348
349
350
351
352
353
354
# File 'lib/cimi/models/schema.rb', line 347

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



366
367
368
# File 'lib/cimi/models/schema.rb', line 366

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

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



374
375
376
# File 'lib/cimi/models/schema.rb', line 374

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

#text(*args) ⇒ Object



361
362
363
364
# File 'lib/cimi/models/schema.rb', line 361

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