Class: SakaiInfo::Metaobj

Inherits:
SakaiObject show all
Includes:
ModProps
Defined in:
lib/sakai-info/metaobj.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ Metaobj

Returns a new instance of Metaobj.



27
28
29
30
31
32
33
34
# File 'lib/sakai-info/metaobj.rb', line 27

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:id]
  @description = dbrow[:description]
  @external_type = dbrow[:externaltype]
  @schema_hash = dbrow[:schema_hash]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



14
15
16
# File 'lib/sakai-info/metaobj.rb', line 14

def dbrow
  @dbrow
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/sakai-info/metaobj.rb', line 14

def description
  @description
end

#external_typeObject (readonly)

Returns the value of attribute external_type.



14
15
16
# File 'lib/sakai-info/metaobj.rb', line 14

def external_type
  @external_type
end

#schema_hashObject (readonly)

Returns the value of attribute schema_hash.



14
15
16
# File 'lib/sakai-info/metaobj.rb', line 14

def schema_hash
  @schema_hash
end

Class Method Details

.all_serializationsObject



188
189
190
191
192
193
194
195
# File 'lib/sakai-info/metaobj.rb', line 188

def self.all_serializations
  [
   :default,
   :mod,
   :instructions,
   :schemadata,
  ]
end

.clear_cacheObject



22
23
24
# File 'lib/sakai-info/metaobj.rb', line 22

def self.clear_cache
  @@cache = {}
end

.find(id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/sakai-info/metaobj.rb', line 36

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:metaobj_form_def].filter(:id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(Metaobj, id)
    end
    @@cache[id] = Metaobj.new(row)
  end
  @@cache[id]
end

Instance Method Details

#alternate_create_xsltObject



103
104
105
106
107
108
109
# File 'lib/sakai-info/metaobj.rb', line 103

def alternate_create_xslt
  if @dbrow[:alternatecreatexslt].nil?
    nil
  else
    @@alternate_create_xslt ||= ContentResource.find_by_uuid(@dbrow[:alternatecreatexslt])
  end
end

#alternate_view_xsltObject



111
112
113
114
115
116
117
# File 'lib/sakai-info/metaobj.rb', line 111

def alternate_view_xslt
  if @dbrow[:alternateviewxslt].nil?
    nil
  else
    @@alternate_view_xslt ||= ContentResource.find_by_uuid(@dbrow[:alternateviewxslt])
  end
end

#default_serializationObject

serialization



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/sakai-info/metaobj.rb', line 132

def default_serialization
  result = {
    "id" => self.id,
    "description" => self.description,
    "owner" => self.owner.serialize(:summary),
    "site" => nil,
    "system_only" => self.system_only?,
    "published" => self.published?,
    "globally_published" => self.globally_published?,
    "pending_approval" => self.pending_approval?,
    "external_type" => self.external_type,
    "alternate_create_xslt" => nil,
    "alternate_view_xslt" => nil,
    "schema_hash" => self.schema_hash,
  }
  if self.site.nil?
    result.delete("site")
  else
    result["site"] = self.site.serialize(:summary)
  end
  if not self.pending_approval?
    result.delete("pending_approval")
  end
  if self.alternate_create_xslt.nil?
    result.delete("alternate_create_xslt")
  else
    result["alternate_create_xslt"] = self.alternate_create_xslt.serialize(:summary)
  end
  if self.alternate_view_xslt.nil?
    result.delete("alternate_view_xslt")
  else
    result["alternate_view_xslt"] = self.alternate_view_xslt.serialize(:summary)
  end
  result
end

#global_stateObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sakai-info/metaobj.rb', line 82

def global_state
  case @dbrow[:globalstate]
  when 0
    "unpublished"
  when 1
    "pending approval"
  when 2
    "published"
  else
    @dbrow[:globalstate]
  end
end

#globally_published?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/sakai-info/metaobj.rb', line 95

def globally_published?
  self.global_state == "published"
end

#instructionsObject



119
120
121
122
123
124
125
# File 'lib/sakai-info/metaobj.rb', line 119

def instructions
  if @dbrow[:instructions].nil?
    nil
  else
    @instructions ||= @dbrow[:instruction].read
  end
end

#instructions_serializationObject



176
177
178
179
180
# File 'lib/sakai-info/metaobj.rb', line 176

def instructions_serialization
  {
    "instructions" => self.instructions,
  }
end

#ownerObject



47
48
49
# File 'lib/sakai-info/metaobj.rb', line 47

def owner
  @owner ||= User.find(@dbrow[:owner])
end

#pending_approval?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/sakai-info/metaobj.rb', line 99

def pending_approval?
  self.global_state == "pending approval"
end

#published?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/sakai-info/metaobj.rb', line 78

def published?
  self.site_state == "published"
end

#schemadataObject



127
128
129
# File 'lib/sakai-info/metaobj.rb', line 127

def schemadata
  @schemadata ||= @dbrow[:schemadata].read.force_encoding(Encoding::UTF_8)
end

#schemadata_serializationObject



182
183
184
185
186
# File 'lib/sakai-info/metaobj.rb', line 182

def schemadata_serialization
  {
    "schemadata" => self.schemadata,
  }
end

#siteObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sakai-info/metaobj.rb', line 55

def site
  if @dbrow[:siteid]
    begin
      @site ||= Site.find(@dbrow[:siteid])
    rescue ObjectNotFoundException
      nil
    end
  else
    nil
  end
end

#site_stateObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/sakai-info/metaobj.rb', line 67

def site_state
  case @dbrow[:sitestate]
  when 0
    "unpublished"
  when 2
    "published"
  else
    @dbrow[:sitestate]
  end
end

#summary_serializationObject



168
169
170
171
172
173
174
# File 'lib/sakai-info/metaobj.rb', line 168

def summary_serialization
  {
    "id" => self.id,
    "description" => self.description,
    "owner" => self.owner.eid,
  }
end

#system_only?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sakai-info/metaobj.rb', line 51

def system_only?
  @dbrow[:systemonly] == 1
end