class CIMI::Model::Base

Public Class Methods

new(values = {}) click to toggle source
# File lib/cimi/models/base.rb, line 126
def initialize(values = {})
  super(values)
  retrieve_entity
end

Public Instance Methods

[]=(a, v) click to toggle source
# File lib/cimi/models/base.rb, line 131
def []=(a, v)
  v = super
  retrieve_entity if a == :id
  v
end
destroy() click to toggle source

Destroy the database attributes for this model

# File lib/cimi/models/base.rb, line 150
def destroy
  @entity.destroy
  self
end
extract_properties!(data) click to toggle source

FIXME: Kludge around the fact that we do not have proper *Create objects that deserialize properties by themselves

# File lib/cimi/models/base.rb, line 157
def extract_properties!(data)
  h = {}
  if data['property']
    # Data came from XML
    h = data['property'].inject({}) do |r,v|
      r[v['key']] = v['content']
      r
    end
  elsif data['properties']
    h = data['properties']
  end
  property ||= {}
  property.merge!(h)
end
ref_id(ref_url) click to toggle source
# File lib/cimi/models/base.rb, line 172
def ref_id(ref_url)
  ref_url.split('/').last if ref_url
end
save() click to toggle source

Save the common attributes name, description, and properties to the database

# File lib/cimi/models/base.rb, line 139
def save
  if @entity
    @entity.name = name
    @entity.description = description
    @entity.properties = property
    @entity.save
  end
  self
end