Module: SakaiInfo::ModProps

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sakai-info/mod_props.rb', line 14

def self.included(klass)
  klass.class_eval {
    # defaults based on User and Site objects
    def get_created_at_key; :createdon; end
    def get_created_by_key; :createdby; end
    def get_modified_at_key; :modifiedon; end
    def get_modified_by_key; :modifiedby; end

    def self.created_at_key(newkey)
      self.class_eval("def get_created_at_key; :#{newkey}; end")
    end

    def self.created_by_key(newkey)
      self.class_eval("def get_created_by_key; :#{newkey}; end")
    end

    def self.modified_at_key(newkey)
      self.class_eval("def get_modified_at_key; :#{newkey}; end")
    end

    def self.modified_by_key(newkey)
      self.class_eval("def get_modified_by_key; :#{newkey}; end")
    end

    def created_by_id
      @dbrow[self.get_created_by_key]
    end

    def created_by
      User.find(self.created_by_id)
    end

    def created_at
      @dbrow[self.get_created_at_key]
    end

    def modified_by_id
      @dbrow[self.get_modified_by_key]
    end

    def modified_by
      User.find(self.modified_by_id)
    end

    def modified_at
      @dbrow[self.get_modified_at_key]
    end

    def mod_serialization
      {
        "created_at" => self.created_at,
        "created_by" => User.get_eid(self.created_by_id),
        "modified_at" => self.modified_at,
        "modified_by" => User.get_eid(self.modified_by_id),
      }
    end

    def mod_details_serialization
      {
        "created_at" => self.created_at,
        "created_by" => self.created_by.serialize(:summary),
        "modified_at" => self.modified_at,
        "modified_by" => self.modified_by.serialize(:summary),
      }
    end
  }
end