Class: SakaiInfo::Alias

Inherits:
SakaiObject show all
Includes:
ModProps
Defined in:
lib/sakai-info/alias.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) ⇒ Alias

Returns a new instance of Alias.



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

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:alias_id]
  @target = dbrow[:target]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



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

def dbrow
  @dbrow
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Class Method Details

.all_serializationsObject



111
112
113
# File 'lib/sakai-info/alias.rb', line 111

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

.clear_cacheObject



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

def self.clear_cache
  @@cache = {}
end

.count_by_site_id(site_id) ⇒ Object



80
81
82
# File 'lib/sakai-info/alias.rb', line 80

def self.count_by_site_id(site_id)
  Alias.query_by_site_id(site_id).count
end

.find(id) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/sakai-info/alias.rb', line 60

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

.find_by_site_id(site_id) ⇒ Object



75
76
77
78
# File 'lib/sakai-info/alias.rb', line 75

def self.find_by_site_id(site_id)
  Alias.query_by_site_id(site_id).all.
    collect { |row| @@cache[row[:alias_id]] = Alias.new(row) }
end

.query_by_site_id(site_id) ⇒ Object



71
72
73
# File 'lib/sakai-info/alias.rb', line 71

def self.query_by_site_id(site_id)
  DB.connect[:sakai_alias].where("target like ?", "%#{site_id}%")
end

Instance Method Details

#default_serializationObject

serialization



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/sakai-info/alias.rb', line 89

def default_serialization
  result = {
    "id" => self.id,
    "target" => self.target,
    "site" => nil,
    "properties" => self.properties,
  }
  if not self.site.nil?
    result["site"] = self.site.serialize(:summary)
  else
    result.delete("site")
  end
  result
end

#propertiesObject



84
85
86
# File 'lib/sakai-info/alias.rb', line 84

def properties
  @properties ||= AliasProperty.find_by_alias_id(self.id)
end

#siteObject



54
55
56
57
58
# File 'lib/sakai-info/alias.rb', line 54

def site
  if not self.site_id.nil?
    @site ||= Site.find(self.site_id)
  end
end

#site_idObject

target types

/mailarchive/channel/<site-id>/main
/site/<site-id>
/announcement/announcement/<site-id> -> rss feed


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sakai-info/alias.rb', line 38

def site_id
  if @target.nil?
    nil
  else
    if @target =~ /^\/site\/(.+)$/
      $1
    elsif @target =~ /^\/mailarchive\/channel\/(.+)\/main$/
      $1
    elsif @target =~ /^\/announcement\/announcement\/(.+)$/
      $1
    else
      nil
    end
  end
end

#summary_serializationObject



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

def summary_serialization
  {
    "id" => self.id,
    "target" => self.target,
  }
end