Method: CIMI::Service::Base.metadata

Defined in:
lib/cimi/service/base.rb

.metadata(attr_name = nil, opts = nil) ⇒ Object

Define the metadata for an attribute; opts must be a Hash that can contain the following entries:

:type : one of 
:constraints : a proc that is passed the current context and
               must return a list of values


180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cimi/service/base.rb', line 180

def self.(attr_name = nil, opts = nil)
   ||= {}
  return  if attr_name.nil? && opts.nil?

  opts[:type] ||= 'text'
  opts[:type] = opts[:type].to_s
  opts[:constraints] ||= lambda { |_| [] }
  unless .include?(opts[:type])
    raise "Metadata type must be one of #{METADATA_TYPES.join(",")}"
  end
  [attr_name] = opts
end