class SakaiInfo::SakaiObject

this class forms the basis of all other Sakai object abstractions

Attributes

id[R]

most objects will have unique IDs (perhaps the rest should generate their own?)

Public Class Methods

all_serializations() click to toggle source

support for CLI – returns an array of symbols that can be passed back to serialize, to_yaml, or to_json should be reimplemented in all object classes

# File lib/sakai-info/sakai_object.rb, line 94
def self.all_serializations
  [:default]
end
descendants() click to toggle source

keep track of descendants

# File lib/sakai-info/sakai_object.rb, line 99
def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end

Public Instance Methods

dbrow_only_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 53
def dbrow_only_serialization
  if not self.dbrow_serialization["dbrow"].nil?
    self.dbrow_serialization["dbrow"]
  else
    {}
  end
end
dbrow_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 43
def dbrow_serialization
  if self.respond_to? :dbrow
    {
      "dbrow" => self.dbrow
    }
  else
    {}
  end
end
default_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 61
def default_serialization
  object_type_serialization
end
object_type_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 37
def object_type_serialization
  {
    "sakai_object_type" => self.class
  }
end
serialize(*q) click to toggle source
# File lib/sakai-info/sakai_object.rb, line 19
def serialize(*q)
  q.flatten!

  if q.length == 0
    q = [:default]
  end

  serialization = {}
  q.each do |sub|
    sub_method_name = (sub.to_s + "_serialization").to_sym
    if self.respond_to? sub_method_name
      serialization = serialization.merge(self.method(sub_method_name).call)
    end
  end

  serialization
end
shell_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 69
def shell_serialization
  summary_serialization
end
summary_serialization() click to toggle source
# File lib/sakai-info/sakai_object.rb, line 65
def summary_serialization
  default_serialization
end
to_csv(*fields) click to toggle source
# File lib/sakai-info/sakai_object.rb, line 81
def to_csv(*fields)
  values = []
  fields.each do |field|
    m = self.method(field.to_sym)
    next if m.nil?
    values << m.call.to_s
  end
  values.collect{|v|"\"#{v}\""}.join(",")
end
to_json(*q) click to toggle source
# File lib/sakai-info/sakai_object.rb, line 77
def to_json(*q)
  serialize(q).to_json
end
to_yaml(*q) click to toggle source
# File lib/sakai-info/sakai_object.rb, line 73
def to_yaml(*q)
  serialize(q).to_yaml
end